I have a ViewPager
Inside a ScrollView
along with other components. When I give a height to ViewPager
in XML
then the ScrollView
works normally but I cant give height for ScrollView
as the ViewPager
should expand according to the page height. I have implemented a runnable which will expand the ViewPager
on runtime.
The problem is I am not able to scroll the outer ScrollView
which is holding the ViewPager
XML =======
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:src="@drawable/img1"
android:scaleType="fitXY"
android:layout_width="match_parent"
android:layout_height="150dp"
android:id="@+id/img_1"
/>
<ViewPager
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ViewPager>
</ScrollView>
JAVA to dynamically set height for viewpager
viewpager.post(new Runnable() {
@Override
public void run() {
ViewGroup.LayoutParams lp = viewpager.getLayoutParams();
lp.height = viewpager.getChildAt(viewpager.getCurrentItem()).getHeight();
viewpager.setLayoutParams(lp);
}
});