Reputation: 1337
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
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
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
Reputation: 52
Did you try :
HorizontalScrollView h = (HorizontalScrollView)findViewById(R.id.scrollview_row_1);
h.setLayoutParams(new HorizontalScrollView.LayoutParams(50,50));
Upvotes: 0