Stack Diego
Stack Diego

Reputation: 1337

Android: resize an HorizontalScrollView

I'm trying to resize at runtime a simple HorizontalScrollView that contains only a Linearlayout this way:

HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.scrollview_row_1);
h.setLayoutParams(new FrameLayout.LayoutParams(50,50));

but then i get this error:

E/AndroidRuntime(5098): FATAL EXCEPTION: main
E/AndroidRuntime(5098): java.lang.ClassCastException: android.widget.FrameLayout$LayoutParams

How should I resize my scrollView properly?

Upvotes: 1

Views: 954

Answers (3)

Matthieu
Matthieu

Reputation: 16417

To be more generic, you can probably just use a ViewGroup.LayoutParams... (so that even if you changed the LinearLayout in the future, you won't have to change that code)

Upvotes: 2

Budius
Budius

Reputation: 39856

that's because the HorizontalScrollView is not inside a FrameLayout. the layout params have to match the root view of your HorizontalScrollView.

Upvotes: 1

Bertrand Hieronymus
Bertrand Hieronymus

Reputation: 52

Did you try :

HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.scrollview_row_1);
h.setLayoutParams(new HorizontalScrollView.LayoutParams(50,50));

Upvotes: 0

Related Questions