Example usage for android.widget RelativeLayout RelativeLayout

List of usage examples for android.widget RelativeLayout RelativeLayout

Introduction

In this page you can find the example usage for android.widget RelativeLayout RelativeLayout.

Prototype

public RelativeLayout(Context context) 

Source Link

Usage

From source file:Main.java

/**
 *
 * @param act//from   w  ww  . j  a  va 2  s. c o m
 * @return
 */
public static RelativeLayout getContainerView(Activity act) {
    // create a new relative layout
    RelativeLayout rl = new RelativeLayout(act);

    // fint the root view of the activity
    ViewGroup fl = (ViewGroup) act.findViewById(android.R.id.content);
    fl = (ViewGroup) fl.getChildAt(0);
    Log.d("DEBUG", "w: " + fl.getWidth() + "h: " + fl.getHeight());

    // Params
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(-1, -1);
    //        new FrameLayout.LayoutParams(-1, -1);
    // add to the root view of the activity
    fl.addView(rl, params);

    return rl;
}

From source file:Main.java

public static ViewGroup getPlacer(ViewGroup container) {
    if (NEEDS_FRAME_LAYOUT_HACK) {
        // Insert RelativeLayout to be able to setMargin because pre-Honeycomb FrameLayout
        // could not handle setMargin properly.
        final ViewGroup placer = new RelativeLayout(container.getContext());
        container.addView(placer);//  w  ww  .j a v  a2  s . co  m
        return placer;
    } else {
        return container;
    }
}

From source file:me.ziccard.secureit.fragment.EmptyFragment.java

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    if ((savedInstanceState != null) && savedInstanceState.containsKey(CONTENT)) {
        mContent = savedInstanceState.getString(CONTENT);
    }/*w  w w .j  a  va2s . com*/

    TextView text = new TextView(getActivity());
    text.setGravity(Gravity.CENTER);
    text.setText(mContent);
    text.setTextSize(20 * getResources().getDisplayMetrics().density);

    RelativeLayout layout = new RelativeLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setGravity(Gravity.CENTER);

    RelativeLayout alert = new RelativeLayout(getActivity());
    RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
            LayoutParams.WRAP_CONTENT);
    params.leftMargin = 20;
    params.rightMargin = 20;
    params.addRule(RelativeLayout.CENTER_HORIZONTAL);
    params.addRule(RelativeLayout.CENTER_IN_PARENT);
    alert.setLayoutParams(params);
    alert.setBackgroundResource(R.drawable.red_back);
    alert.setPadding(30, 0, 30, 0);
    alert.addView(text);
    layout.addView(alert);

    return layout;
}

From source file:es.uma.lcc.lockpic.SelectorActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    Button btnForward, btnBack, btnFaces;
    RelativeLayout layout = new RelativeLayout(this);
    layout.setBackgroundResource(R.drawable.background_gradient);

    mPath = getIntent().getStringExtra("path");

    SelectorActivityBundle bundle = (SelectorActivityBundle) getLastCustomNonConfigurationInstance();
    if (bundle != null) {
        mDrawView = new DrawView(this, mPath, false);
        mDrawView.setRectangles(bundle.getRectangles());
        mDrawView.setViewMode(bundle.getViewMode());
        mDrawView.setAspectRate(bundle.getAspectRate());
    } else {//from w w w.  ja va2  s.co  m
        mDrawView = new DrawView(this, mPath, true);
    }
    mDrawView.setId(1);

    RelativeLayout.LayoutParams lpDrawView = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpDrawView.addRule(RelativeLayout.CENTER_VERTICAL);
    mDrawView.setLayoutParams(lpDrawView);
    layout.addView(mDrawView, lpDrawView);

    btnForward = new Button(this);
    btnForward.setText(R.string.selectorForwardButton);
    btnForward.setId(2);
    btnForward.setOnClickListener(new forwardButtonListener());
    RelativeLayout.LayoutParams lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
            LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
    layout.addView(btnForward, lpButton);

    btnBack = new Button(this);
    btnBack.setText(R.string.selectorBackButton);
    btnBack.setId(3);
    btnBack.setOnClickListener(new backButtonListener());
    lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
    layout.addView(btnBack, lpButton);

    btnFaces = new Button(this);
    btnFaces.setText(R.string.facesButton);
    btnFaces.setId(4);
    btnFaces.setOnClickListener(new FacesButtonListener());
    if (!isViewSelectingRegions())
        btnFaces.setVisibility(View.INVISIBLE);
    lpButton = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
    lpButton.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
    lpButton.addRule(RelativeLayout.CENTER_HORIZONTAL);
    layout.addView(btnFaces, lpButton);

    setContentView(layout);
}

From source file:eu.scialom.salarycalc.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    activity = this;

    // Create layout
    this.lMain = new RelativeLayout(this);
    @SuppressWarnings("deprecation")
    final RelativeLayout.LayoutParams lParams = new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT,
            LayoutParams.FILL_PARENT);//  w ww.  j a v a2s. c  o  m
    this.setContentView(this.lMain, lParams);

    // Create tabs
    this.tabs = new Vector<MyTab>();
    this.tabs.add(new MainTab(this));
    this.tabs.add(new OptionTab(this));
    this.tabs.add(new AboutTab(this));

    this.getSupportActionBar().setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
    for (final MyTab it : this.tabs) {
        final ActionBar.Tab t = this.getSupportActionBar().newTab();
        t.setText(it.getShortName());
        t.setTabListener(this);
        this.getSupportActionBar().addTab(t);

        this.lMain.addView(it.getView());
    }

    if (null != savedInstanceState)
        this.curTab = savedInstanceState.getInt("tab", 0);
    this.getSupportActionBar().setSelectedNavigationItem(this.curTab);
}

From source file:com.cloudkick.monitoring.Check.java

@Override
public View getItemView(Context context, View convertView, ViewGroup parent) {
    RelativeLayout checkView;/*  www  . j a v  a  2s .com*/

    String inflater = Context.LAYOUT_INFLATER_SERVICE;
    LayoutInflater li = (LayoutInflater) context.getSystemService(inflater);

    if (convertView == null) {
        checkView = new RelativeLayout(context);
        li.inflate(R.layout.node_detail, checkView, true);
    }

    else {
        checkView = (RelativeLayout) convertView;
    }

    ((TextView) checkView.findViewById(R.id.detail_label)).setText(summary);
    ((TextView) checkView.findViewById(R.id.detail_symbol)).setTextColor(latestState.stateColor);
    ((TextView) checkView.findViewById(R.id.detail_symbol)).setText(latestState.stateSymbol);
    ((TextView) checkView.findViewById(R.id.detail_value)).setText(latestState.status);

    return checkView;
}

From source file:org.telegram.ui.ChangePhoneHelpActivity.java

@Override
public View createView(Context context) {
    actionBar.setBackButtonImage(R.drawable.ic_ab_back);
    actionBar.setAllowOverlayTitle(true);

    TLRPC.User user = UserConfig.getCurrentUser();
    String value;/* w  w  w. j  a  va 2  s  .  co m*/
    if (user != null && user.phone != null && user.phone.length() != 0) {
        value = PhoneFormat.getInstance().format("+" + user.phone);
    } else {
        value = LocaleController.getString("NumberUnknown", R.string.NumberUnknown);
    }

    actionBar.setTitle(value);
    actionBar.setActionBarMenuOnItemClick(new ActionBar.ActionBarMenuOnItemClick() {
        @Override
        public void onItemClick(int id) {
            if (id == -1) {
                finishFragment();
            }
        }
    });

    fragmentView = new RelativeLayout(context);
    fragmentView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            return true;
        }
    });

    RelativeLayout relativeLayout = (RelativeLayout) fragmentView;

    ScrollView scrollView = new ScrollView(context);
    relativeLayout.addView(scrollView);
    RelativeLayout.LayoutParams layoutParams3 = (RelativeLayout.LayoutParams) scrollView.getLayoutParams();
    layoutParams3.width = LayoutHelper.MATCH_PARENT;
    layoutParams3.height = LayoutHelper.WRAP_CONTENT;
    layoutParams3.addRule(RelativeLayout.CENTER_VERTICAL, RelativeLayout.TRUE);
    scrollView.setLayoutParams(layoutParams3);

    LinearLayout linearLayout = new LinearLayout(context);
    linearLayout.setOrientation(LinearLayout.VERTICAL);
    linearLayout.setPadding(0, AndroidUtilities.dp(20), 0, AndroidUtilities.dp(20));
    scrollView.addView(linearLayout);
    ScrollView.LayoutParams layoutParams = (ScrollView.LayoutParams) linearLayout.getLayoutParams();
    layoutParams.width = ScrollView.LayoutParams.MATCH_PARENT;
    layoutParams.height = ScrollView.LayoutParams.WRAP_CONTENT;
    linearLayout.setLayoutParams(layoutParams);

    ImageView imageView = new ImageView(context);
    imageView.setImageResource(R.drawable.phone_change);
    linearLayout.addView(imageView);
    LinearLayout.LayoutParams layoutParams2 = (LinearLayout.LayoutParams) imageView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    imageView.setLayoutParams(layoutParams2);

    TextView textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 16);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    //textView.setTextColor(0xff212121);

    try {
        textView.setText(AndroidUtilities
                .replaceTags(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp)));
    } catch (Exception e) {
        FileLog.e("tmessages", e);
        textView.setText(LocaleController.getString("PhoneNumberHelp", R.string.PhoneNumberHelp));
    }
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(56);
    textView.setLayoutParams(layoutParams2);

    textView = new TextView(context);
    textView.setTextSize(TypedValue.COMPLEX_UNIT_DIP, 18);
    textView.setGravity(Gravity.CENTER_HORIZONTAL);
    textView.setTextColor(ContextCompat.getColor(context, R.color.colorAccent) /*0xff4d83b3*/);
    textView.setText(LocaleController.getString("PhoneNumberChange", R.string.PhoneNumberChange));
    textView.setTypeface(AndroidUtilities.getTypeface("fonts/rmedium.ttf"));
    textView.setPadding(AndroidUtilities.dp(16), AndroidUtilities.dp(12), AndroidUtilities.dp(16),
            AndroidUtilities.dp(12));
    textView.setBackground(context.getDrawable(R.drawable.list_selector));
    linearLayout.addView(textView);
    layoutParams2 = (LinearLayout.LayoutParams) textView.getLayoutParams();
    layoutParams2.width = LayoutHelper.WRAP_CONTENT;
    layoutParams2.height = LayoutHelper.WRAP_CONTENT;
    layoutParams2.gravity = Gravity.CENTER_HORIZONTAL;
    layoutParams2.leftMargin = AndroidUtilities.dp(20);
    layoutParams2.rightMargin = AndroidUtilities.dp(20);
    layoutParams2.topMargin = AndroidUtilities.dp(46);
    textView.setLayoutParams(layoutParams2);

    textView.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            if (getParentActivity() == null) {
                return;
            }
            AlertDialog.Builder builder = new AlertDialog.Builder(getParentActivity());
            builder.setTitle(LocaleController.getString("AppName", R.string.AppName));
            builder.setMessage(LocaleController.getString("PhoneNumberAlert", R.string.PhoneNumberAlert));
            builder.setPositiveButton(LocaleController.getString("OK", R.string.OK),
                    new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialogInterface, int i) {
                            presentFragment(new ChangePhoneActivity(), true);
                        }
                    });
            builder.setNegativeButton(LocaleController.getString("Cancel", R.string.Cancel), null);
            showDialog(builder.create());
        }
    });

    return fragmentView;
}

From source file:org.chronotext.MobileTest.Bridge.java

public Bridge(Activity activity) {
    super(activity);

    // ---/*from w w  w .java  2s. c om*/

    switch (testMode) {
    case GLVIEW_ATTACHED_AND_VISIBLE_AT_START:
        hidden = false;
        detached = false;
        break;

    case GLVIEW_ATTACHED_AND_HIDDEN_AT_START:
        hidden = true;
        detached = false;
        break;

    default:
    case GLVIEW_NOT_ATTACHED_AT_START:
        hidden = false;
        detached = true;
        break;
    }

    hasRootView = CAN_BE_HIDDEN || CAN_BE_DETACHED || hidden || detached;

    // ---

    setViewProperties(new GLView.Properties().setEGLContextClientVersion(1).setPreserveEGLContextOnPause(true));

    if (hasRootView) {
        rootView = new RelativeLayout(activity);
        rootView.setBackgroundColor(Color.YELLOW);
        activity.setContentView(rootView);
    }

    if (!detached) {
        if (hidden) {
            getView().setVisibility(View.GONE);
        }

        if (hasRootView) {
            rootView.addView(getView());
        } else {
            activity.setContentView(getView());
        }
    }

    // ---    

    overlayView = new RelativeLayout(activity);
    activity.addContentView(overlayView, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    button1 = addButton(100, 100, 1);
    button2 = addButton(100, 200, 2);

    refreshButtons();
}

From source file:com.applivery.applvsdklib.ui.views.update.MustUpdateViewImpl.java

/**
 * Overrided in order to get fullScreen dialog
 * @param savedInstanceState//from   w ww.  j  a v  a 2 s  .  c om
 * @return
 */
@Override
public Dialog onCreateDialog(final Bundle savedInstanceState) {

    final RelativeLayout root = new RelativeLayout(getActivity());
    root.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
            ViewGroup.LayoutParams.MATCH_PARENT));

    final Dialog dialog = new Dialog(getActivity());
    dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
    dialog.setContentView(root);
    dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.YELLOW));
    dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);

    return dialog;
}

From source file:net.pocketmagic.android.carousel.MainActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //no keyboard unless requested by user
    getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

    // compute screen size and scaling
    Singleton.getInstance().InitGUIFrame(this);

    int padding = m_Inst.Scale(10);
    // create the interface : full screen container
    RelativeLayout panel = new RelativeLayout(this);
    panel.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
    panel.setPadding(padding, padding, padding, padding);
    panel.setBackgroundDrawable(new GradientDrawable(GradientDrawable.Orientation.TOP_BOTTOM,
            new int[] { Color.WHITE, Color.GRAY }));
    setContentView(panel);/* ww w .j a  v a2s . c om*/

    // copy images from assets to sdcard
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma1.png", "plasma1.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma2.png", "plasma2.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma3.png", "plasma3.png", false);
    AppUtils.AssetFileCopy(this, "/mnt/sdcard/plasma4.png", "plasma4.png", false);

    //Create carousel view documents
    ArrayList<CarouselDataItem> Docus = new ArrayList<CarouselDataItem>();
    for (int i = 0; i < 1000; i++) {
        CarouselDataItem docu;
        if (i % 4 == 0)
            docu = new CarouselDataItem("/mnt/sdcard/plasma1.png", 0, "First Image " + i);
        else if (i % 4 == 1)
            docu = new CarouselDataItem("/mnt/sdcard/plasma2.png", 0, "Second Image " + i);
        else if (i % 4 == 2)
            docu = new CarouselDataItem("/mnt/sdcard/plasma3.png", 0, "Third Image " + i);
        else
            docu = new CarouselDataItem("/mnt/sdcard/plasma4.png", 0, "4th Image " + i);
        Docus.add(docu);
    }

    // add the serach filter
    EditText etSearch = new EditText(this);
    etSearch.setHint("Search your documents");
    etSearch.setSingleLine();
    etSearch.setTextColor(Color.BLACK);
    etSearch.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_menu_search, 0, 0, 0);
    AppUtils.AddView(panel, etSearch, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_TOP } }, -1,
            -1);
    etSearch.addTextChangedListener((TextWatcher) this);

    // add logo
    TextView tv = new TextView(this);
    tv.setTextColor(Color.BLACK);
    tv.setText("www.pocketmagic.net");
    AppUtils.AddView(panel, tv, LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT, new int[][] {
            new int[] { RelativeLayout.CENTER_HORIZONTAL }, new int[] { RelativeLayout.ALIGN_PARENT_BOTTOM } },
            -1, -1);

    // create the carousel
    CarouselView coverFlow = new CarouselView(this);

    // create adapter and specify device independent items size (scaling)
    // for more details see: http://www.pocketmagic.net/2013/04/how-to-scale-an-android-ui-on-multiple-screens/
    m_carouselAdapter = new CarouselViewAdapter(this, Docus, m_Inst.Scale(400), m_Inst.Scale(300));
    coverFlow.setAdapter(m_carouselAdapter);
    coverFlow.setSpacing(-1 * m_Inst.Scale(150));
    coverFlow.setSelection(Integer.MAX_VALUE / 2, true);
    coverFlow.setAnimationDuration(1000);
    coverFlow.setOnItemSelectedListener((OnItemSelectedListener) this);

    AppUtils.AddView(panel, coverFlow, LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT,
            new int[][] { new int[] { RelativeLayout.CENTER_IN_PARENT } }, -1, -1);
}