如何通过代码更改ANDROID的UI布局
16lz
2022-03-06
阅读更多 有如下一个XML的页面布局(略去一些东东)
android:id="@+id/1"
android:id="@+id/2"
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);
加粗部分就是取得原有的布局参数,然后再变更,通过此方法,可以变更很多原有的布局参数
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);
加粗部分就是取得原有的布局参数,然后再变更,通过此方法,可以变更很多原有的布局参数
更多相关文章
- android之相机开发
- Android之Handler用法总结
- android animation中的参数interpolator详解
- Android(安卓)ormlite 框架介绍
- Android(安卓)实现联网——在线程中联网
- 浅谈Java中Collections.sort对List排序的两种方法
- mybatisplus的坑 insert标签insert into select无参数问题的解决
- Python技巧匿名函数、回调函数和高阶函数
- Python list sort方法的具体使用