簡體   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