这是我的文字和图片及文字视图(i1,t1,t2)。如何在我的类文件中动态格式化这些视图的宽度和高度。
ImageView i1 = new ImageView(this);
TextView t1 = new TextView(this);
TextView t2 = new TextView(this);
RelativeLayout rl1 = new RelativeLayout(this);
RelativeLayout.LayoutParams innerLP1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
innerLP1.addRule(RelativeLayout.CENTER_IN_PARENT);
innerLP1.topMargin=(30);
t1.setText(name);
rl1.setLayoutParams(innerLP1);
rl1.addView(t1);
答案 0 :(得分:0)
将布局参数设置为那些视图
RelativeLayout.LayoutParams view_params = new
RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
imageview.setLayoutParams(view_params );
textview.setLayoutParams(view_params );
答案 1 :(得分:0)
使用txt.SetHeight()
方法。
答案 2 :(得分:0)
使用setHeight()& setWidth()方法。例如:
ImageView i1 = new ImageView(this);
i1.setHeight(xxx);
i1.setWidth(xxx);