0

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 cannot find a way to imitate the android:layout_below= xml attribute in the java UI approach.

2 Answers 2

2

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);
Sign up to request clarification or add additional context in comments.

Comments

1
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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.