我有相对布局,即 main.xml ,其设置如下。但是现在我必须将view1放置在view2上,其的宽度为200dp,高度为100dp的,以使view2变大,view1变小。
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>
最佳答案
您想实现什么?如果您只想更改宽度和高度,而不是:
RelativeLayout rl = (RelativeLayout) findViewById(R.id.yourId);
rl.getLayoutParams().height = 100;
rl.getLayoutParams().width = 100;
关于android - 以编程方式更改相对布局,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/10631807/