相关疑难解决方法(0)

当RecyclerView适合屏幕时,不要折叠工具栏


我使用Android Design Library创建了一个应用程序,带有工具栏和TabLayout.
实际上有2个选项卡,都有2个RecyclerView,滚动时会自动折叠工具栏.

我的问题是:当RecyclerView具有少量项目并完全适合屏幕时(如TAB 2中),我可以禁用工具栏折叠吗?

我见过很多像CheeseSquare这样的例子,由Google员工制作,问题仍然存在:即使RecyclerView只有1个项目,工具栏仍然隐藏在滚动上.

在此输入图像描述

我想我可以找出是否在屏幕上显示RecyclerView的第一项,如果是,则禁用工具栏折叠.前者易于实现,后者又如何呢?

这是我的布局:

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fitsSystemWindows="true"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed"
            android:background="?attr/colorPrimary"
            app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/glucosio_pink"
            app:tabSelectedTextColor="@android:color/white"
            app:tabIndicatorColor="@color/glucosio_accent"
            app:tabTextColor="#80ffffff"/>
        </android.support.design.widget.AppBarLayout>

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

    <android.support.design.widget.FloatingActionButton
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/main_fab"
        android:layout_margin="16dp"
        android:onClick="onFabClicked"
        app:backgroundTint="@color/glucosio_accent"
        android:src="@drawable/ic_add_black_24dp"
        android:layout_gravity="bottom|right"
        />
    </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)




android toolbar android-appcompat android-recyclerview android-design-library

34
推荐指数
4
解决办法
1万
查看次数

在内容滚动而不是ToolBar上隐藏TabLayout

我想在滚动我的内容时隐藏TabLayout.目前我在网上搜索但我找到了隐藏工具栏的示例,但我想隐藏TabLayout.所以请帮助我.我试过下面的代码.

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/main_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/id_appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/id_tabs"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize" 
            style="@style/MyCustomTabLayout"/>

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

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

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

以下是示例应用程序:https : //play.google.com/store/apps/details id = com.contextlogic.wish https://play.google.com/store/apps/details?id = co.vine .android

android android-support-design

21
推荐指数
2
解决办法
2万
查看次数

滚动没有内容时如何禁用CollapsingToolbar崩溃?

我正在使用android支持设计'com.android.support:design:22.2.1'我的问题是当滚动没有内容时,折叠工具栏仍然启用折叠操作.如果滚动中没有内容,我需要删除视图的折叠.

我的XML:

  <android.support.design.widget.CoordinatorLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            xmlns:app="http://schemas.android.com/apk/res-auto"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true">

            <android.support.design.widget.AppBarLayout
                android:id="@+id/appbar"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:background="@android:color/white"
                android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">

                <android.support.design.widget.CollapsingToolbarLayout
                    android:id="@+id/collapsing_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:fitsSystemWindows="true"
                    app:contentScrim="?attr/colorPrimary"
                    app:expandedTitleMarginEnd="64dp"
                    app:expandedTitleMarginStart="48dp"
                    app:layout_scrollFlags="scroll|exitUntilCollapsed">

                    <fragment
                        android:id="@+id/pawfile_header"
                        android:name="com.lightbulb.pawesome.fragments.PawfileHeaderFragment"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginLeft="10dp"
                        android:layout_marginTop="10dp"
                        android:fitsSystemWindows="true"
                        app:layout_collapseMode="parallax" />

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

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

            <fragment
                android:id="@+id/pawfile_timeline"
                android:name="com.lightbulb.pawesome.user_timeline.PawesomeUserTimelineFragment"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

UDPATE问题:

我已经完成了禁用和启用视图折叠的功能.我使用这行代码来禁用折叠:

AppBarLayout.LayoutParams appbarParams = (AppBarLayout.LayoutParams)     collapsingToolbar.getLayoutParams();
appbarParams.setScrollFlags(0);
collapsingToolbar.setLayoutParams(p);
Run Code Online (Sandbox Code Playgroud)

问题是appbar强制将scrollflags的高程设置为0.我尝试使用appbar.setElevation(0),但它没有任何效果.如何从我的appbar中删除高程?

android scroll toolbar android-collapsingtoolbarlayout

15
推荐指数
1
解决办法
2万
查看次数

当NestedScrollView为空时,停止AppBarLayout滚动屏幕

我有一个相当典型的List功能,使用CoordinatorLayout,AppBarLayout,SwipeRefreshLayout和RecyclerView -

当RecyclerView有足够的内容滚动时,页面似乎很好.当RecyclerView为空或者没有足够的内容可以滚动时,行为是AppBarLayout子节点app:layout_scrollFlags="scroll|enterAlwaysCollapsed"将继续滚动 - 这看起来很奇怪.

当NestedScrollView为空时,有没有办法阻止AppBarLayout子项滚动?

在此输入图像描述

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.CoordinatorLayout
        android:id="@+id/coordinatorLayout"
        android:background="@android:color/transparent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@android:color/transparent"
            android:elevation="4dp">

            <LinearLayout
                android:id="@+id/eventHeader"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:padding="16dp"
                android:background="@color/green"
                android:orientation="horizontal"
                app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

                <View
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="1"/>

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="scroll|enterAlwaysCollapsed"
                    android:textColor="@color/white"
                    android:textSize="15sp"/>

                <View
                    android:layout_width="0dp"
                    android:layout_height="0dp"
                    android:layout_weight="1"/>

            </LinearLayout>

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

        <android.support.v4.widget.SwipeRefreshLayout
            android:id="@+id/swipeToRefresh"
            android:layout_width="match_parent"
            android:layout_gravity="fill_vertical"
            android:layout_height="match_parent"
            app:layout_behavior="@string/appbar_scrolling_view_behavior">

            <android.support.v7.widget.RecyclerView
                android:id="@+id/recyclerView"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"
                android:dividerHeight="0dp"
                android:layout_gravity="fill_vertical"
                android:drawSelectorOnTop="true"
                android:listSelector="@drawable/selector_ripple_grey_transparent"
                android:scrollbars="vertical"/>

        </android.support.v4.widget.SwipeRefreshLayout>

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

    <TextView
        android:id="@+id/noData"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:padding="16dp"
        android:text="@string/no_data_available"
        android:textSize="17sp"/>

</FrameLayout>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-appbarlayout

14
推荐指数
1
解决办法
4605
查看次数

折叠工具栏 - 禁用触摸滚动

我想禁用折叠工具栏的触摸行为滚动.如果由RecyclerView(正在工作)触发,它应该只是折叠.我想为什么不只是禁用焦点... android:focusableInTouchMode="false" 但它不起作用.我可以改变layout_scrollFlags但是然后...我的问题是,有一个简单的解决方案吗?

XML:

<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=".MainActivity">

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/mCollapsingToolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/header_size"
            android:fitsSystemWindows="true"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                ...
                app:layout_collapseMode="parallax"/>

            <android.support.v7.widget.Toolbar
                android:id="@+id/mToolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:layout_collapseMode="pin" />

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

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

    <android.support.v7.widget.RecyclerView
        ...
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>

</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-collapsingtoolbarlayout

3
推荐指数
1
解决办法
4160
查看次数