2017-07-27 68 views
0

我知道這似乎是一個重複的問題,但我不明白爲什麼我不能將Tablayout放置在我的ViewPager頂部。Android的傳呼機隱藏標籤佈局,如果它位於它的頂部

<RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="200dp"> 


      <android.support.design.widget.TabLayout 
       android:id="@+id/tl_ads" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_gravity="bottom" 
       android:layout_alignParentBottom="true" 
       app:tabBackground="@drawable/tab_selector" 
       app:tabGravity="center" 
       app:tabIndicatorHeight="0dp" 
       app:tabMaxWidth="16dp" 
       app:tabPadding="2dp"/> 


      <android.support.v4.view.ViewPager 
       android:id="@+id/vp_ads" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:background="@android:color/white" 
       android:elevation="2dp" 
       android:translationZ="2dp" 
       tools:targetApi="lollipop"/> 





     </RelativeLayout> 

如果我用LinearLayout替換RelativeLayout,除非不是我想要的,Tablayout工作得很好。

回答

0

以下試試可能會對你有所幫助。 錯誤的位置:安卓:layout_alignParentBottom = 「真」 enter image description here

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 


<android.support.design.widget.TabLayout 
    android:id="@+id/tl_ads" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="#9ad195" 
    android:minHeight="?attr/actionBarSize" /> 


<android.support.v4.view.ViewPager 
    android:id="@+id/vp_ads" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/tl_ads" 
    android:background="#cccccc" 
    android:elevation="2dp" 
    android:translationZ="2dp" 
    tools:targetApi="lollipop" /> 

+0

謝謝,但是這不是我wan't。我需要TabLayout顯示在viewpager之上。 我試過FrameLayout,它也沒有工作。 –

+0

回答編輯檢查 –

+0

在這種情況下Viewpager覆蓋TabLayout。 –