2017-07-27 26 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。 –

相关问题