我要实现的布局是TabLayout在屏幕下方
//正常TabLayout在布局上方,老板改需求,TabLayout要放在布局下面
以下是正常的布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v4.view.ViewPager
android:id="@+id/main_viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_tabLayout"
app:tabSelectedTextColor="#FF9100"
/>
</android.support.v4.view.ViewPager>
</LinearLayout>
如何操作才能实现老板的需求?
首先在布局中把TabLayout放在ViewPager下面
<android.support.v4.view.ViewPager
android:id="@+id/main_viewPager"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="0dp"/>
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/main_tabLayout"
app:tabSelectedTextColor="#FF9100"
/>
ViewPager的高度如果是match_parent就会把TabLayout顶没,这里提供一种方法:
可以使用weight权重,设置ViewPager为1,TabLayout还是wrap_content,
这时候屏幕会留出一段空间使TabLayout显示出来
Ok