0

I have a ViewPager in my application that act as a slider. My problem is I want to my view pager's size matches it's child size (the loaded image).

<RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content">

                <android.support.v4.view.ViewPager
                    android:layout_width="match_parent"
                    android:layout_height="200dp"
                    android:id="@+id/slider_viewpager"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentTop="true"
                    />
                <com.viewpagerindicator.CirclePageIndicator
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:id="@+id/slider_indicator"
                    android:layout_alignParentBottom="true"
                    android:layout_centerHorizontal="true"
                    android:padding="10dp"
                    />
            </RelativeLayout>

My page item :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:wheel="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/slider_layout">

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/image"
        android:layout_alignParentBottom="true">
    </ImageView>


    <com.pnikosis.materialishprogress.ProgressWheel
        android:id="@+id/progressBar"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        wheel:matProg_barColor="@color/primaryColor"
        wheel:matProg_progressIndeterminate="true" />
</RelativeLayout>

but with this layout my view pager height become 0 when the images loaded after some time from a url. How can I make my View pager gets It's size from It's child? (something like WRAP_CONTENT)

====

I changed LayoutParams dynamically after received the BitMap images but that doesn't worked and the result size become bigger that it supposed to be.Something like below :

RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(bitmap.getMeasuredWidth(),bitmap.getMeasuredHeight());
                    image.setLayoutParams(params);
                    pager.setLayoutParams(params);
Hamidreza Salehi
  • 930
  • 2
  • 10
  • 22
  • change this : `android:layout_height="wrap_content"` to this : `android:layout_height="match_parent"` – Paul Jul 21 '15 at 15:29
  • for which widget should i use match_parent? for `ImageView` of or the `ViewPager`? what about that `RelativeLayout` that contains `ImageView`. I know that we can't have a circular dependency in `RelativeLayout`. – Hamidreza Salehi Jul 22 '15 at 03:51

0 Answers0