6

Which class do I have to use, when setting the LayoutParams of my LinearLayout? The following two are not working:

  1. linLayout.setLayoutParams(new ViewGroup.LayoutParams(50,50));
  2. linLayout.setLayoutParams(new android.widget.LinearLayout.LayoutParams(50,50));

if I get the params first, change them and set them back it's working. So I suppose the Params I get returned inherit from ViewGroup.LayoutParams...

Any idea? THX

1 Answer 1

12

Use the LayoutParams of the parent. So in case your LinearLayout is a child of RelativeLayout then you use linLayout.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(50,50));

Sign up to request clarification or add additional context in comments.

4 Comments

crazy, thats cool :) why use these params and not the LinearLayout params?
I don't know an exact answer, but LayoutParams are used by views to tell their parents how they want to be laid out. And this is parent specific (depends on the parent Layout type). So also when you are you are casting linlayout.getLayoutParams, cast it to (RelativeLayout.LayoutParams) in this case.
That is one of the stupidess designs I've ever seen. Setting it on the parent? Seriously, WTF?
@AndroidDev :/ u need to understand it a little more

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.