怎么通过代码更改ANDROID的UI布局
如何通过代码更改ANDROID的UI布局
有如下一个XML的页面布局(略去一些东东)
<RelativeLayout
android:id="@+id/1"
<RelativeLayout
android:id="@+id/2"
<RelativeLayout
android:id="@+id/3"
android:layout_below="@+id/1"
当需要动态改为3的BELOW(android:layout_below="@+id/1")时,可通过如下方法变更:
lay = this.findViewById(R.id.3);
RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) lay.getLayoutParams();
layoutParams.addRule(RelativeLayout.BELOW,2);
lay .setLayoutParams(layoutParams);
加粗部分就是取得原有的布局参数,然后再变更,通过此方法,可以变更很多原有的布局参数
有如下一个XML的页面布局(略去一些东东)
<RelativeLayout
android:id="@+id/1"
<RelativeLayout
android:id="@+id/2"
<RelativeLayout
android:id="@+id/3"
android:layout_below="@+id/1"
当需要动态改为3的BELOW(android:layout_below="@+id/1")时,可通过如下方法变更:
lay = this.findViewById(R.id.3);
RelativeLayout.LayoutParams layoutParams = (android.widget.RelativeLayout.LayoutParams) lay.getLayoutParams();
layoutParams.addRule(RelativeLayout.BELOW,2);
lay .setLayoutParams(layoutParams);
加粗部分就是取得原有的布局参数,然后再变更,通过此方法,可以变更很多原有的布局参数