如果选项卡位于其顶部,则Android寻呼机会隐藏它

时间:2017-07-27 15:34:31

标签: android android-viewpager android-tablayout

我知道这似乎是一个重复的问题,但我不明白为什么我不能将Tablayout置于我的ViewPager之上。

LengthAwarePaginator {#217 ▼
  #total: 75000
  #lastPage: 37500
  #items: Collection {#213 ▼
    #items: array:2 [▼
      0 => Customer {#220 ▼
        #table: "customers"
        #connection: null
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:5 [▼
          "id" => 1
          "customer_number" => "46071600600"
          "name" => "Nikodem Zalewski"
          "customer_contact" => "507614445"
          "customer_type" => "P"
        ]
        #original: array:5 [▶]
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #events: []
        #observables: []
        #relations: array:1 [▼
          "contracts" => Collection {#224 ▼
            #items: array:2 [▼
              0 => Contract {#227 ▼
                #connection: null
                #table: null
                #primaryKey: "id"
                #keyType: "int"
                +incrementing: true
                #with: []
                #perPage: 15
                +exists: true
                +wasRecentlyCreated: false
                #attributes: array:10 [▶]
                #original: array:10 [▶]
                #casts: []
                #dates: []
                #dateFormat: null
                #appends: []
                #events: []
                #observables: []
                #relations: []
                #touches: []
                +timestamps: true
                #hidden: []
                #visible: []
                #fillable: []
                #guarded: array:1 [▶]
              }
              1 => Contract {#229 ▶}
            ]
          }
        ]
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #fillable: []
        #guarded: array:1 [▶]
      }
      1 => Customer {#221 ▼
        #table: "customers"
        #connection: null
        #primaryKey: "id"
        #keyType: "int"
        +incrementing: true
        #with: []
        #perPage: 15
        +exists: true
        +wasRecentlyCreated: false
        #attributes: array:5 [▶]
        #original: array:5 [▼
          "id" => 2
          "customer_number" => "81050371854"
          "name" => "Adam Wróbel"
          "customer_contact" => "560047958"
          "customer_type" => "P"
        ]
        #casts: []
        #dates: []
        #dateFormat: null
        #appends: []
        #events: []
        #observables: []
        #relations: array:1 [▼
          "contracts" => Collection {#222 ▼
            #items: []
          }
        ]
        #touches: []
        +timestamps: true
        #hidden: []
        #visible: []
        #fillable: []
        #guarded: array:1 [▶]
      }
    ]
  }
  #perPage: 2
  #currentPage: 1
  #path: "*"
  #query: []
  #fragment: null
  #pageName: "page"
}

如果我将RelativeLayout替换为Linearlayout,那么Tablayout的效果会很好,除非这不是我想要的。

2 个答案:

答案 0 :(得分:0)

  

尝试以下可能会对您有所帮助。   这里出错:android:layout_alignParentBottom =“true”   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" />

答案 1 :(得分:0)

试试这个:

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

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

    <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"/>
</RelativeLayout>

在RelativeLayout中,窗口小部件按照声明的顺序依次添加。您先声明了标签布局,然后声明了ViewPager。因此,您的选项卡正在创建,但被ViewPager隐藏,占用了整个RelativeLayout。