Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing relative layout programmatically

Tags:

android

I've relative layout i.e. main.xml which I set as follows. But now I've to put view1 on view2 with width=200dp and height =100dp, so that view2 will be large one and view1 will be small one on it.

public void onCreate(Bundle savedInstanceState) 
         {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
         }

main.xml

  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <RelativeLayout
    android:id="@+id/MainPanel"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@id/panel_bottom"
    android:layout_gravity="center_horizontal" >

    <com.proj.demo.view1
        android:id="@+id/sheet"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignWithParentIfMissing="true"
        android:layout_centerInParent="true"
        android:layout_toLeftOf="@+id/panel_quick_buttons"
        />

    <com.proj.demo.view2
        android:id="@+id/sheet2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_alignWithParentIfMissing="true"
        android:layout_centerInParent="true"
        android:layout_toLeftOf="@+id/panel_quick_buttons"
      />

</RelativeLayout>
</RelativeLayout>
like image 937
user1400285 Avatar asked May 17 '12 07:05

user1400285


People also ask

What is the difference between relative layout and FrameLayout?

RelativeLayout : is a ViewGroup that displays child views in relative positions. AbsoluteLayout : allows us to specify the exact location of the child views and widgets. TableLayout : is a view that groups its child views into rows and columns. FrameLayout : is a placeholder on screen that is used to display a single ...

Can we use RelativeLayout inside ConstraintLayout?

You can't use relative layout directly inside constraint layout. Intention of ConstraintLayout is to optimize and flatten the view hierarchy of your layouts by applying some rules to each view to avoid nesting.


1 Answers

What do you want to achieve? If you just want to change width and heigh than:

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId);
    rl.getLayoutParams().height = 100;
    rl.getLayoutParams().width = 100;
like image 200
goodm Avatar answered Sep 23 '22 22:09

goodm