`
leng_cn
  • 浏览: 298415 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

如何通过代码更改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);

加粗部分就是取得原有的布局参数,然后再变更,通过此方法,可以变更很多原有的布局参数
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics