问题
I have a ListView
each item of which is ViewPager
with some content (mostly images). Everything works fine bot not on Android 4.3 and above ViewPager
's content is missing and ViewPager not scrollable. I don't know which part of source code to provide here - ask me and I'll try to provide you maximum info.
EDIT: Found out that ViewPager in my case has zero dimensions. But only on Android 4.3+.
Here is part of my layout:
<...AdaptableHeightImageView
android:id="@android:id/icon"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:src="@drawable/slide"
android:visibility="invisible"
tools:ignore="ContentDescription" />
<...UninterceptableViewPager
android:id="@+id/list_item_showcase_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@android:id/icon"
android:overScrollMode="never" />
When I set ViewPager
's width and height 100dp for example it becomes visible.
The UninterceptableViewPager
is ViewPager
subclass with locked X-axes. The AdaptableHeightImageView
is ImageView
subclass which fits the setted width but stretches it's height to save aspect ratio. The goal is to have ViewPager
with the same dimensions that ImageView
has.
If I write something like this:
<...UninterceptableViewPager
android:id="@+id/list_item_showcase_images"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="@android:id/icon"
android:layout_alignLeft="@android:id/icon"
android:layout_alignRight="@android:id/icon"
android:layout_alignTop="@android:id/icon"
android:overScrollMode="never" />
Then once my Views
inside ViewPager
or parent ListView
are recycled they never appear again. Also in this case any ViewPager
content which wasn't shown when data array is set will never be shown. But ViewPager
will have dimensions and I even able to scroll it. Seems like Google changed something in Android 4.3.
In conclusion: everything works fine only if I set concrete width and height
来源:https://stackoverflow.com/questions/20093858/viewpager-on-android-4-3-missing-content