0

这是我的文本和图像以及文本视图(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);
4

3 回答 3

0

为这些视图设置布局参数

RelativeLayout.LayoutParams view_params = new 
          RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                                      RelativeLayout.LayoutParams.WRAP_CONTENT);
imageview.setLayoutParams(view_params );
textview.setLayoutParams(view_params );
于 2012-05-23T06:10:39.017 回答
0

使用txt.SetHeight()方法。

于 2012-05-23T06:12:10.917 回答
0

使用 setHeight() 和 setWidth() 方法。例如:

     ImageView i1 = new ImageView(this);
     i1.setHeight(xxx);
     i1.setWidth(xxx); 
于 2012-05-23T06:21:09.353 回答