开发者

Layout Views in LinearLayout Programmatically

开发者 https://www.devze.com 2023-02-22 22:11 出处:网络
I am trying to position a TextView and an ImageView within a LinearLayout programmatically. The problem is that the textview is always on top of the imageview, and I would like to it be underneath. I

I am trying to position a TextView and an ImageView within a LinearLayout programmatically. The problem is that the textview is always on top of the imageview, and I would like to it be underneath. I c开发者_StackOverflow中文版annot find a way to imitate the android:layout_below= xml attribute in the java UI approach.


You should simply switch the order of your two views.

For example:

linear.addView(image);
linear.addView(text);

instead of:

linear.addView(text);
linear.addView(image);


LinearLayout lin = new LinearLayout(context);
lin.setOrientation(LinearLayout.VERTICAL);

ImageView imageView = new ImageView(context);
TextView textView = new TextView(context);

lin.addView(imageView);
lin.addView(textView);

the first component ImageView should be placed in the LinearLayout first, before the TextView.

Edit: oops forgot about "programmatically"

0

精彩评论

暂无评论...
验证码 换一张
取 消