简体   繁体   中英

Adding ViewPager inside a RelativeLayout

I am working on Android ViewPager. I wrote code which can create ViewPager and also another layout having some controls. I would like to show my other controls first. then i want to show the viewpage (having tabs).

Problem is: it shows viewpage layout first(relativeLayoutVP) and then my other control layout (relativeLayoutControl) is showing onto the relativeLayoutVP. Like this.

Below is my xml code. This problem was discussed already 1 year ago ( Android viewpager under RelativeLayout ) but no solution came. Hence i repeat again here. Apology for the duplicate question.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#fa6a6a" >

<RelativeLayout
    android:id="@+id/relativeLayoutVP"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true">

    <android.support.v4.view.ViewPager
        android:id="@+id/vp_main"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.v4.view.ViewPager>
</RelativeLayout>

<RelativeLayout
    android:id="@+id/relativeLayoutControl"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#171717" >

    <ImageButton
        android:id="@+id/menu_button"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_marginLeft="12dp"
        android:background="@drawable/ic_launcher" />

    <ImageView
        android:id="@+id/image"
        android:layout_width="wrap_content"
        android:layout_height="7.0mm"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true"
        android:background="@drawable/ic_launcher" />

    <ToggleButton
        android:id="@+id/button_search"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:layout_marginRight="12dp"
        android:background="@drawable/ic_launcher"
        android:padding="2dip"
        android:textOff=""
        android:textOn="" />

</RelativeLayout>

Just switch places. Place relativeLayoutControl RealtiveLayout to be the first child and set relativeLayoutVP RelativeLayout to be second child and that is it. Hope this will help someone, because question is really old :)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM