Android里用代码设置View的相关属性
来源:互联网 发布:java api监控系统性能 编辑:程序博客网 时间:2024/06/03 21:31
1.setPading
- Button btn1 = (Button) findViewById(R.id.magic);
- btn1.setPadding(10, 10, 10, 10);
2.setMargin
- Button btn1 = (Button) findViewById(R.id.magic);
- LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(btn1.getLayoutParams());
- lp.setMargins(10, 10, 10, 10);
- lp.leftMargin=10;
- lp.rightMargin=10;
- lp.topMargin=10;
- lp.bottomMargin=10;
可以把设置margin的方式封装成方法,只要是GroupView里面的LayoutParams 即可。
- public static void setMargins (View v, int l, int t, int r, int b) {
- if (v.getLayoutParams() instanceof ViewGroup.MarginLayoutParams) {
- ViewGroup.MarginLayoutParams p = (ViewGroup.MarginLayoutParams) v.getLayoutParams();
- p.setMargins(l, t, r, b);
- v.requestLayout();
- }
- }
- Button btn1 = (Button) findViewById(R.id.magic);
- btn1.getLayoutParams().width=100;
- btn1.getLayoutParams().height=100;
QQ交流群:6399844
0 0
- Android里用代码设置View的相关属性
- Android里用代码设置View的相关属性
- 关于android view属性的归属以及如何在代码中设置相关属性总结
- android在代码中设置View的属性
- Android 代码动态改变View的属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- Android在代码中调用XML中设置的自定义View属性
- android中如何在代码中直接设置View的layout_weight属性
- Android View(四)-View相关属性详解
- android webview效果的相关属性设置
- 【Tech-Android-View】Android中listview的属性设置
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
- 每天学一点MATLAB函数——文件编程函数
- windows nginx tomcat redis 集群
- 问题解决---未能将网站配置为使用ASP.NET4.0
- 关于字节数组的流对象介绍和案例分析
- (2) Linux中diff与patch用法
- Android里用代码设置View的相关属性
- 淘宝SPM解读
- bzoj 1208[HNOI 2004] 宠物收养所
- Linux下百度云盘报 获取bdstoken失败
- 6.UITableView增强
- IOS 2D绘图
- 深入理解HTTP协议
- 案例分析:把指定的信息输出到指定的文件中
- Struts2之validate数据校验两种方式