【问题标题】:TabLayout covered content in fragmentsTabLayout 覆盖片段中的内容
【发布时间】:2018-11-21 17:25:53
【问题描述】:

我最近添加了一个TabLayout 包裹在一个之前包含toolbarAppBarLayout 中,但现在由TabLayout 托管的片段,应该在它下面,被TabLayout 覆盖,我已尝试将android:layout_below="@+id/tablayout" 添加到我的ViewPager(其中包含片段),并将app:layout_behavior="@string/appbar_scrolling_view_behavior" 添加到TabLayout 本身,但是这两种方法都不起作用, 这是我的布局文件的代码:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
    tools:context="com.jackz314.todo.MainActivity"
    android:id="@+id/total_main_bar"
    >

    <include
        android:id="@+id/include"
        layout="@layout/content_main"
        app:layout_anchor="@+id/app_bar_layout"
        app:layout_anchorGravity="left|bottom"
        />

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/app_bar_layout"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:tabMode="fixed"
            app:tabGravity="fill" />

    </android.support.design.widget.AppBarLayout>

</android.support.design.widget.CoordinatorLayout>

请注意,片段的布局包含在“content_main”中,它位于该包含部分中。我对 Android 还是很陌生,因此非常感谢任何形式的帮助或建议。

【问题讨论】:

    标签: android-layout android-fragments android-viewpager android-tablayout android-appbarlayout


    【解决方案1】:

    在检查和修改布局文件中的各种内容后,我将 ViewPager 从包含的布局文件移动到包含 TabLayout 的同一文件中,然后将 app:layout_behavior="@string/appbar_scrolling_view_behavior" 应用于 ViewPager 修复了问题。 (如果它不在您的字符串文件中,android.support.design.widget.AppBarLayout$ScrollingViewBehavior 就是它的值)

    坦率地说,我仍然很困惑为什么这会起作用(因为我尝试将相同的属性应用于包含部分,但没有奏效),所以如果有人可以帮助我解决这个问题,那就太好了.

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-05
      • 2023-03-06
      • 2022-08-18
      • 2015-09-18
      • 2018-10-01
      • 1970-01-01
      相关资源
      最近更新 更多