The type of the LayoutParams
you must use is specified by the type of Layout that encapsulates the thing you want to change params for.
So for example if you want to change LayoutParams
for your LinearLayout
you need to check what's the Layout type that encapsulates it. In your case LinearLayout
is being encapsulated by RelativeLayout
so you need to use RelativeLayout.LayoutParams
instead of ViewGroup.LayoutParams
.
LinearLayout
inside RelativeLayout
in your xml file (activity_main.xml). Use RelativeLayout.LayoutParams
to solve this issue.
Change this:
ll.setLayoutParams(new ViewGroup.LayoutParams(100,200));
to:
ll.setLayoutParams(new RelativeLayout.LayoutParams(100,200));