iㅤ 2022-03-26 11:05 采纳率: 0%
浏览 130

Android 主界面底部导航栏TabLayout 遮挡Fragment中的RecyclerView

问题遇到的现象

由于使用Fragment的原因,activity_main就用的TabLayout,然后具体内容在碎片中写,但是activity_main中TabLayout会遮挡Fragment的内容

我的解答思路和尝试过的方法

又由于设置了TabLayout的背景色,透明度 如果使用marginBottom 其实会让TabLayout的透明度收到影响 就不使用marginBottom

我想要达到的结果

有什么办法能不遮挡碎片内容嘛

activity_main:TabLayout

<?xml version="1.0" encoding="utf-8"?>
<com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout
    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:orientation="vertical"
    tools:context=".MainActivity"
    android:background="@color/white"
    android:fitsSystemWindows="true">

    <androidx.viewpager2.widget.ViewPager2
        android:id="@+id/home_viewPager2"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <!--选项卡指示器Indicator 选项卡容器相关Ripple-->
    <com.google.android.material.tabs.TabLayout
        android:id="@+id/home_tabLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:background="#CCFFFFFF"
        android:minHeight="?attr/actionBarSize"
        app:tabIndicatorAnimationMode="elastic"
        app:tabIndicatorColor="#FFCCCC"
        app:tabIndicatorGravity="top"
        app:tabRippleColor="#CCFFFFFF"
        app:tabSelectedTextColor="#FFCCCC"
        app:tabTextColor="#929299"
        app:tabUnboundedRipple="true">

        <com.google.android.material.tabs.TabItem
            android:id="@+id/item_chat"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/item_find"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <com.google.android.material.tabs.TabItem
            android:id="@+id/item_person"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

    </com.google.android.material.tabs.TabLayout>

</com.google.android.material.circularreveal.coordinatorlayout.CircularRevealCoordinatorLayout>

碎片内容Fragment

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".Person.PersonFragment">

    <com.google.android.material.appbar.MaterialToolbar
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="@color/black"
        app:layout_scrollFlags="scroll|enterAlways|snap" />

    <androidx.core.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <com.youth.banner.Banner
                android:id="@+id/Home_Banner"
                android:layout_width="match_parent"
                android:layout_height="250dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginBottom="10dp"
                app:banner_radius="12dp" />

            <androidx.recyclerview.widget.RecyclerView
                android:id="@+id/Home_Goods"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp" />
        </LinearLayout>
    </androidx.core.widget.NestedScrollView>

</LinearLayout>

  • 写回答

1条回答 默认 最新

  • 立青_ 2022-03-26 13:40
    关注

    你ViewPager2垂直方向别match_parent啊

    评论

报告相同问题?

问题事件

  • 创建了问题 3月26日

悬赏问题

  • ¥15 深度学习残差模块模型
  • ¥20 两个不同Subnet的点对点连接
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)