小编use*_*285的帖子

以编程方式更改相对布局

我有相对布局,即main.xml,我设置如下.但是现在我要把view1放在view2上,宽度= 200dp,高度= 100dp,这样view2就会很大,而view1就会很小.

public void onCreate(Bundle savedInstanceState) 
         {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
         }
Run Code Online (Sandbox Code Playgroud)

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>
Run Code Online (Sandbox Code Playgroud)

android

5
推荐指数
1
解决办法
2万
查看次数

标签 统计

android ×1