开发者

Layout Views in LinearLayout Programmatically

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜