6

我有相对布局,即main.xml,我设置如下。但是现在我必须将 view1 放在 view2 上,width=200dp 和 height =100dp,这样 view2 就会很大,而 view1 会很小。

public void onCreate(Bundle savedInstanceState) 
         {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.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>
4

1 回答 1

29

你想达到什么目标?如果您只想更改宽度和高度:

    RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId);
    rl.getLayoutParams().height = 100;
    rl.getLayoutParams().width = 100;
于 2012-05-17T08:22:56.073 回答