Android里用代码设置View的相关属性
2014-12-16 17:28
337 查看
1.setPading
2.setMargin
可以把设置margin的方式封装成方法,只要是GroupView里面的LayoutParams
即可。
3.set Width Height
QQ交流群:6399844
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;这个LayoutParams是根据该view在不同的GroupView而不同的
可以把设置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(); } }
3.set Width Height
Button btn1 = (Button) findViewById(R.id.magic); btn1.getLayoutParams().width=100;
btn1.getLayoutParams().height=100;
QQ交流群:6399844
相关文章推荐
- Android里用代码设置View的相关属性
- 关于android view属性的归属以及如何在代码中设置相关属性总结
- android webview效果的相关属性设置
- UITableView 表视图 代码设置相关属性
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- android在代码中设置View的属性
- android中如何在代码中直接设置View的layout_weight属性
- android中如何在代码中直接设置View的layout_weight属性
- Android控件WebView的属性设置和相关常用方法总结
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
- android中如何在代码中直接设置View的layout_weight属性
- Android 通过Java代码生成创建界面。动态生成View,动态设置View属性。addRules详解
- Android在代码中调用XML中设置的自定义View属性
- android 用代码设置margin属性,textView加粗
- android中如何在代码中直接设置View的layout_weight属性
- Android 关于WebView的相关属性
- android代码中动态设置布局中控件的属性