2015-05-03 40 views
0

我正在使用Android ViewPager。我編寫了可以創建ViewPager的代碼,以及另一個具有一些控件的佈局。我想首先顯示我的其他控件。那麼我想顯示查看頁面(有選項卡)。在RelativeLayout中添加ViewPager

問題是:它首先顯示viewpage佈局(relativeLayoutVP),然後我的其他控件佈局(relativeLayoutControl)顯示在relativeLayoutVP上。像this.

下面是我的xml代碼。這個問題在1年前已經討論過了(Android viewpager under RelativeLayout),但沒有解決方案。因此我在這裏重複一遍。重複問題的道歉。

<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> 

+0

你需要關閉你的relativelayout父標籤 – BIW

+0

我認爲這不是一個問題。其實我已經關閉了relativelayout父標記,遺憾的是這裏沒有顯示。還有其他建議嗎? – mirzapinku

+0

我可以從你提供的代碼中想到任何好友,對不起 – BIW

回答

0

只需切換的地方。放置relativeLayoutControl RealtiveLayout成爲第一個孩子,並將relativeLayoutVP RelativeLayout設置爲第二個孩子,就是這樣。希望這將有助於某人,因爲問題是真的老:)

相關問題