0

i have a ImageView under each page of ViewPager, the code of PageAdapter is below:

@Override
    public Object instantiateItem(ViewGroup container, int position) {
        ImageView imageView = new ImageView(mContext);
        imageView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,ViewGroup.LayoutParams.WRAP_CONTENT));
        container.addView(imageView);
        imageView.setImageURI(uri);
        return imageView;
        }

but when displaying tall images, i found that the viewpager will resize the image and the wrap_content attribute can not work. the layout file is below:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:fresco="http://schemas.android.com/apk/res-auto"
tools:context="com.weiwa.ljl.testimageview.MainActivity"
android:orientation="vertical">

<!-- TODO: Update blank fragment layout -->
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="1">
        <com.weiwa.ljl.testimageview.ImageViewPager
            android:id="@+id/guide_viewpager"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1">
        </com.weiwa.ljl.testimageview.ImageViewPager>
</LinearLayout>
</LinearLayout>

i have tried the onMeasure method on this thread: android-i-am-unable-to-have-viewpager-wrap-content and layout_weight method on this thread: ViewPager not working if set layout_height = wrap_content but both cannot work, please help me.

Community
  • 1
  • 1
cmnewfan
  • 129
  • 1
  • 9

0 Answers0