android - 修复了 TabLayout 和 Content 重叠的 AppBar

标签 android androiddesignsupport

TabLayout scroll

有了新的 Android 支持设计库,AppBar 有了一些很酷的功能。

我正在考虑实现与上面的 gif 中所示相同的滚动效果。 (取自 Google Play 游戏 -> 我的游戏)

我看过将以下属性添加到 nestedscrollview,将内容放在应用栏上方。

app:behavior_overlapTop

当 appbar 内的所有组件都设置为滚动时,它按预期工作。

app:layout_scrollFlags="scroll"

如果我想让 TabLayout 固定在顶部,它下面的空间也会被固定。所以它看起来很奇怪:

My implementation

简而言之,有什么方法可以使用新的设计库创建上述内容,还是我必须以其他方式制作?

请求的 XML:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/content"
    android:layout_height="match_parent"
    android:layout_width="match_parent">

    <android.support.design.widget.AppBar
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="164dp"
        android:background="?attr/colorPrimary">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_scrollFlags="scroll"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlways"/>

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

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        app:behavior_overlapTop="32dp"/>

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

最佳答案

试试这个,希望它的工作

在工具栏中设置app:layout_scrollFlags="scroll|enterAlways" 和 TabLayout 中的 android:scrollbars="horizo​​ntal"

根据我的建议,您应该在 TabLayout 中删除此行 app:layout_scrollFlags="scroll|enterAlways"

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:app1="http://schemas.android.com/apk/res/com.samsung.ssc"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
tools:context="com.samsung.ssc.LMS.LMSListActivity">

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fitsSystemWindows="true">

    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorPrimary"
        android:elevation="4dp"
        android:minHeight="?attr/actionBarSize"
        app:layout_scrollFlags="scroll|enterAlways">


    </android.support.v7.widget.Toolbar>

    <android.support.design.widget.TabLayout
        android:id="@+id/tabLayoutLMSList"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:scrollbars="horizontal">


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

<android.support.v4.view.ViewPager
    android:id="@+id/viewpagerLMSList"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />


<android.support.design.widget.FloatingActionButton
    android:id="@+id/fabCreateNewLMS"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentEnd="true"
    android:layout_alignParentRight="true"
    android:layout_gravity="right|bottom"
    android:layout_margin="@dimen/margin_15"
    android:onClick="onNewLeaveCreateClick"
    android:src="@drawable/ems_pencil"
    app1:rippleColor="@color/ems_status_sky_blue_color"
    app:backgroundTint="@color/ems_status_yellow_color"
    app:borderWidth="@dimen/margin_0"
    app:elevation="@dimen/margin_5" />

关于android - 修复了 TabLayout 和 Content 重叠的 AppBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31651785/

相关文章:

android - 在运行方法之前等待 Activity 恢复

android - AlarmManager.RTC 不工作?

Android 地理围栏在某些手机(如 OnePlus、小米等)中不会触发

android - 试图在 ImageView 中获取图像的显示大小

android - 如何在 CollapsingToolbarLayout android 中设置子标题

Android RecyclerView 项目上方有空隙

android - 使用导航 View 和工具栏不显示后退按钮

android - 如何在多段线路径上为 google map v2 标记设置动画?

android - 如果出现错误,如何以编程方式请求关注 TextInputLayout?

android - 当我使用设计支持库时 ClassNotFoundException