Miguel Andrade
Miguel Andrade

Reputation: 376

Center fragment in ViewPager

I trying to achieve one layout like this:

enter image description here

The problem is that i cant center fragment on viewpager. I already try to change gravitys, and everything but i cant. There is some of mycode:

 <android.support.design.widget.CollapsingToolbarLayout
        >


        <RelativeLayout
            android:fitsSystemWindows="true"
            android:layout_width="match_parent"
            android:layout_height="match_parent">


            <android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentStart="true"
                android:layout_alignParentTop="true"
                android:layout_weight="1"
                android:gravity="center" />



        </RelativeLayout>
       (...)
    </android.support.design.widget.CollapsingToolbarLayout>

Fragment child have that code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
    android:id="@+id/infos"
    android:weightSum="3"
    android:layout_alignParentBottom="true"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
      (...)</LinearLayout>

With this code im geting something like this:

enter image description here

Upvotes: 1

Views: 298

Answers (1)

Cao Minh Vu
Cao Minh Vu

Reputation: 1950

Please update your layout like this:

<android.support.v4.view.ViewPager
                android:id="@+id/pager"
                android:layout_width="match_parent"
                android:layout_height="190dp"
                android:layout_marginTop="25dp"
                android:paddingLeft="25dp"
                android:paddingRight="25dp"
                />
Feel free to tailor padding/height to fit your UI. 

Upvotes: 1

Related Questions