ClassCastException when adding LayoutParams

What class should I use when setting up the LayoutParams my LinearLayout ? The following two do not work:

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

if I get the parameters first, change them and return their work. Therefore, I assume that the returned Params are inherited from ViewGroup.LayoutParams ...

Any idea? thanks

+6
source share
1 answer

Use the parent's LayoutParams. Therefore, if your LinearLayout is a child of RelativeLayout, you use linLayout.setLayoutParams(new android.widget.RelativeLayout.LayoutParams(50,50));

+12
source

Source: https://habr.com/ru/post/893595/


All Articles