用TabLayout结合ViewPager实现TabLayout在屏幕下方显示的效果

我要实现的布局是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

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值