Venugopal
Venugopal

Reputation: 1298

change linear layout height programmatically in Android

I am trying to change the height of linear layout programmatically. When I use

ll.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT));

I am getting exception:

java.lang.ClassCastException: android.view.ViewGroup$LayoutParams

Upvotes: 3

Views: 20901

Answers (3)

Matt
Matt

Reputation: 3847

My guess is you're importing a different LayoutParams. Try a fully qualified version:

ll.setLayoutParams(new android.view.ViewGroup.LayoutParams(
    android.view.ViewGroup.LayoutParams.FILL_PARENT,
    android.view.ViewGroup.LayoutParams.WRAP_CONTENT
));

Upvotes: 3

Venugopal
Venugopal

Reputation: 1298

I got the solution LinearLayout.LayoutParams class as

ll.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT));

Upvotes: 8

Swayam
Swayam

Reputation: 16354

When you first include LayoutParams in your code and hit Cntrl+Shift+Enter to automatically import the required files, you are displayed a list of all the packages. Make sure you import the right package in your code.

import android.view.ViewGroup.LayoutParams;

Upvotes: 1

Related Questions