繁体   English   中英

如何在这里设置ImageView和TextView的宽度和高度?

[英]how to set the width and height of ImageView and TextView here?

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

将布局参数设置为这些视图

RelativeLayout.LayoutParams view_params = new 
          RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, 
                                      RelativeLayout.LayoutParams.WRAP_CONTENT);
imageview.setLayoutParams(view_params );
textview.setLayoutParams(view_params );

使用txt.SetHeight()方法。

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

     ImageView i1 = new ImageView(this);
     i1.setHeight(xxx);
     i1.setWidth(xxx); 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM