标签: android-appbarlayout

ViewHolder中的嵌套RecyclerView会破坏折叠工具栏布局

我有一个在CoordinatorLayout中托管的垂直RecyclerView,具有折叠工具栏布局.此RecyclerView的ViewHolder包含另一个带有GridLayoutManager的RecyclerView.

这种嵌套的原因是内部RecyclerView显示的图片集合可以包含1-20张图片.我不知道会有多少张图片,但Grid的跨度必须始终为3.每次绑定ViewHolder时,我都会调整RecyclerView的布局参数以容纳内容.

如果没有CollapsingToolBarLayout,这很有效.但是,如果有一个折叠的工具栏,用我的手指在内部RecyclerView上滚动不会滚动折叠工具栏,但滚动另一个项目却会.

要重新强调,在绑定的ViewHolder中,如果我开始滚动除嵌套的RecyclerView之外的任何其他项目,滚动工作正常.但是,如果我在嵌套的RecyclerView上开始滚动,那么它会中断.

是否可以阻止内部RecyclerView上的滚动拦截,只允许父滚动?我希望内部的RecyclerView仍能处理点击.

以下是该现象的YouTube链接:https://youtu.be/fzj7HmqskzU

以下是父RecyclerView的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=".MainActivityFragment">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recycler_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="vertical"
    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

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

    <android.support.design.widget.CollapsingToolbarLayout
        android:id="@+id/collapsing_toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:elevation="4dp"
        app:contentScrim="?attr/colorPrimary"
        app:layout_collapseParallaxMultiplier="0.7"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <View
            android:id="@+id/header_view"
            android:layout_width="match_parent"
            android:layout_height="192dp"
            android:animateLayoutChanges="true"
            android:background="@color/primary" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/action_bar"
            android:layout_width="match_parent"
            android:layout_height="@dimen/abc_action_bar_default_height_material"
            android:elevation="4dp"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/Theme.AppCompat.NoActionBar"
            app:theme="@style/Theme.AppCompat.NoActionBar" />
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
Run Code Online (Sandbox Code Playgroud)

这是托管嵌套RecyclerView的主要ViewHolder:

public class SimpleAdapter extends RecyclerView.Adapter<SimpleAdapter.ViewHolder> {

private static final int MODEL_OBJECT = 1;

private List<ModelObject> modelObjects;

private Context context;

private int imageSize;

public SimpleAdapter(List<ModelObject> modelObjects) …
Run Code Online (Sandbox Code Playgroud)

android-recyclerview androiddesignsupport android-collapsingtoolbarlayout android-appbarlayout

8
推荐指数
2
解决办法
2619
查看次数

ListView嵌套在API <21上滚动

标题很清楚.我有这个布局:

_________________
|_______________| <- Toolbar    
|___|___|___|___| <- Tablayout
|               |
|               |
|   ViewPager   |
|               |
|_______________|
Run Code Online (Sandbox Code Playgroud)

工具栏和tablayout都在一个内部AppBarLayout,所以我可以使用滚动标记来隐藏工具栏向上滚动.问题是这只适用于嵌套滚动支持的视图.大多数标签 - 我的意思是,大多数页面 - 是support.v4.NestedScrollViews,所以这是可以的; 其他人(并且需要)ListView.

从Lollipop开始,我可以简单地添加android:nestedScrollingEnabled="true"到列表视图,并且工具栏在滚动时正确隐藏.

但是,在API <21上,没有这样的属性,工具栏也不会隐藏.更重要的是,列表中的最后一项是隐藏的,因为有一些测量错误CoordinatorLayout:listview就好像它有工具栏当前占用的空间一样.

解决方案:

  • 切换到RecyclerView,它支持嵌套滚动:我不能,因为我需要使用只适用于适配器视图的外部库适配器,并且我无法替换(即,ParseQueryAdapter);

  • 扩展ListView和实现嵌套滚动:似乎很复杂;

  • 扩展ListView并实现一些解决方法,例如测量东西以避免最后一项问题或(和)自定义行为以使工具栏隐藏:似乎也很复杂;

  • 使用一些布局技巧:找不到.

有帮助吗?

例如,我(拼命)尝试:

<android.support.v4.widget.NestedScrollView
    android:nestedScrollingEnabled="true"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </ListView>

</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

但是这种方式ListView并没有被列为match_parent.我得到一个小高度的小视图,页面的其余部分是空的.

android android-listview android-support-library android-design-library android-appbarlayout

8
推荐指数
1
解决办法
9265
查看次数

AppBarLayout的嵌套RecyclerView问题

我的活动包含设计库23.0.1提供的AppBarLayout,它在我向上滚动时隐藏.我有一个RecyclerView,每个子项目也包含一个RecyclerView,基本上是一个嵌套的RecyclerView.

我的问题是,当我触摸任何内部RecyclerView的孩子并向上滚动时,AppBar不会隐藏.但是,如果我将手指放在其他地方(不在内部RecyclerView上)并滚动,则应用栏会向上滚动.为什么会这样?我甚至尝试为内部回收站视图添加appbar行为,但是当我触摸其他地方并滚动时,应用栏只会向上滚动.

注意:内部的recyclerview有一组固定的项目,这些项目在任何时候都是可见的,基本上,在recyclerview中没有滚动.

有一个类似的问题,提供的解决方案是拦截内部回收视图的触摸并将其传递给父回收站视图.但是这会禁用内部回收站视图中子项的单击事件,我不希望这样.

android android-recyclerview android-design-library android-appbarlayout

8
推荐指数
1
解决办法
1058
查看次数

如何同步两个CoordinatorLayout + AppBarLayout的滚动

我有一个XML活动.

就像是:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    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:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

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

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

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/primary"
                android:theme="@style/ToolbarStyle"
                android:gravity="center_vertical"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                style="@style/bold" />

            <android.support.design.widget.TabLayout
                android:id="@+id/tabs"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:theme="@style/TabLayoutStyle"
                android:animateLayoutChanges="true"
                app:tabGravity="fill"
                app:tabMode="fixed"
                app:tabTextAppearance="@style/TabStyle"/>

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

        <com.wedmegood.planner.view.XViewPager
            android:id="@+id/main_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="fill_vertical"
            app:layout_behavior="@string/appbar_scrolling_view_behavior" />

        ...

</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)

FragmentViewPagerCoordinatorLayoutAppBarLayout+ CollapsingToolbarLayout.

Fragment的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:id="@+id/root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/primaryDark"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:fitsSystemWindows="true"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"> …
Run Code Online (Sandbox Code Playgroud)

android android-coordinatorlayout android-collapsingtoolbarlayout android-appbarlayout

8
推荐指数
2
解决办法
2627
查看次数

如何在WebView上正确实现NestedScrollingChild

NestedScrollView提供的支持库不正确地与工作WebView(相关错误报告).因此我已经开始实现NestedScrollingChilda WebView并且它似乎对第一个滚动工作正常,折叠和扩展AppBarLayout但是任何后续滚动都无法折叠它.

我的WebView:

import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.support.v4.view.NestedScrollingChild;
import android.support.v4.view.NestedScrollingChildHelper;
import android.util.AttributeSet;
import android.view.View;
import android.webkit.WebView;

/**
 * Created by carlos on 2/19/16.
 */
public class MyWebView extends WebView implements NestedScrollingChild {
    private static final String TAG = MyWebView.class.getSimpleName();
    private NestedScrollingChildHelper helper = new NestedScrollingChildHelper(this);

    public MyWebView(Context context) {
        super(context);
    }

    public MyWebView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public MyWebView(Context context, AttributeSet …
Run Code Online (Sandbox Code Playgroud)

android webview android-support-library android-collapsingtoolbarlayout android-appbarlayout

8
推荐指数
1
解决办法
1883
查看次数

即时查看跳转和闪烁,但animateLayoutChanges ="true"

我让我的TabLayout用动画的android:animateLayoutChanges ="真"AppBarLayout.但是当我设置TabLayout.setVisibility(View.GONE)时,我的片段的容器立即上升到ActionBar几毫秒.然后它返回到TabLayout的末尾并将其上升到ActionBar.我在下面的gif上解释了这个.

关注gif

由于某些原因,TabLayout背后的理论实践按钮,但是当隐藏TabLayout动画时,启动FrameContainer,将我的视图固定在TabLayout的底部.

我录制了一段视频来说明这种行为.Dropbox视频播放器跳过一些帧和动画似乎很好.这就是为什么,要注意这个错误,你可以在电脑上加载视频,并以高质量观看5秒和11秒.视频

我的LayoutXML:

<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:orientation="vertical">

<SurfaceView
    android:layout_width="0px"
    android:layout_height="0px"/>

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

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


    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?attr/colorPrimary"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        android:visibility="gone"
        app:tabGravity="fill"
        app:tabIndicatorColor="@android:color/white"
        app:tabMode="fixed"/>

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

<android.support.v4.widget.DrawerLayout
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <!--
        This FrameLayout holds my fragments.
    -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/outer_background">

        <ProgressBar
            android:id="@+id/main_load_progress"
            android:layout_width="wrap_content" …
Run Code Online (Sandbox Code Playgroud)

android android-animation android-fragments material-design android-appbarlayout

8
推荐指数
1
解决办法
1792
查看次数

为AppBarLayout设置提升/ StateListAnimator时,Android JNI崩溃

我正在尝试将a的高程设置AppBarLayout为0(并返回到默认值).它崩溃了一些时间(并不总是),在API 21(> = 22等工作正常)崩溃.

我正在使用StateListAnimator以下链接中描述的(因为它是自support-lib 24.0.0以来设置高程的"官方"方式):

/sf/answers/2659465651/


我的实际方法如下所示:

public void setAppBarElevation(final boolean visible) {
  if (appBar != null && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    appBar.setStateListAnimator(AnimatorInflater.loadStateListAnimator(this, (visible) ? R.animator.appbar_elevated : R.animator.appbar_not_elevated));
  }
}
Run Code Online (Sandbox Code Playgroud)

连同两个XML文件(另一个是设置android:valueTo="0"):

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item>
    <objectAnimator android:propertyName="elevation"
                    android:valueTo="@dimen/default_appbar_elevation"
                    android:valueType="floatType"/>
  </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

我已经测试了一些具有不同Android版本的设备(API 19,21,23,24,25),并且它只在21上崩溃.

日志显示设置高程时出现了一些JNI错误(来自StateListAnimator我认为):

   --------- beginning of system
JNI DETECTED ERROR IN APPLICATION: cant call void android.view.View.setElevation(float) on null object
    in call to CallVoidMethodV
    from …
Run Code Online (Sandbox Code Playgroud)

java-native-interface android android-support-library android-elevation android-appbarlayout

8
推荐指数
1
解决办法
819
查看次数

是否可以使用Android上的协调器布局将状态栏与工具栏一起滚动?

我想知道是否可以滚动整个状态栏(图标和背景),而不仅仅是背景.几乎就好像它是工具栏的一部分.

我遇到了与下面问题相同的情况,不同之处在于我想知道我是否可以滚动整个状态栏以使背景变得不透明 - 这就是我认为以下查询的理想结果

Android状态栏以协调器布局向上滚动,使状态图标与工具栏标题重叠

这是一张图

在此输入图像描述

这是我的代码

<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"
    android:fitsSystemWindows="true"
    tools:context="me.hugopretorius.wishlizt.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay"
        app:contentScrim="#000">

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

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />

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

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

    <io.github.yavski.fabspeeddial.FabSpeedDial
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        app:fabGravity="bottom_end"
        app:fabMenu="@menu/menu_fab"
        app:miniFabBackgroundTint="@android:color/white"
        app:miniFabDrawableTint="?attr/colorPrimaryDark"
        app:miniFabTitleTextColor="?attr/colorPrimaryDark" />

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

android android-toolbar android-coordinatorlayout android-appbarlayout

8
推荐指数
1
解决办法
830
查看次数

How to have a collapsing of top view into a smaller sized view?

This question was asked before in a too broad and unclear way here, so I've made it much more specific, with full explanation and code of what I've tried.

Background

I'm required to mimic the way the Google Calendar has a view at the top, that can animate and push down the view at the bottom, yet it has extra, different behavior. I've summarized what I'm trying to do on 3 characteristics:

  1. Pressing on the toolbar will always work, …

android android-collapsingtoolbarlayout android-appbarlayout

8
推荐指数
1
解决办法
4177
查看次数

Android 辅助功能 - 无法专注于 Appbar 中的任何元素

我在我的 2 个活动中遇到了这个问题。当我使用键盘 Tab 键或箭头键导航时 - 我无法到达应用栏中的任何元素。

1) 活动 1 -> 我的 appbar 有一个汉堡菜单图标来访问 NavigationView。我无法单击此图标。如果我触摸菜单图标 - 我可以使用键盘在菜单项上下导航。但是我如何进入菜单?

2) 活动 2 - 我有一个 CoordinatorLayout,里面有一个 CollapsingToolbarLayout 和一个 NestedScrollView。我能够导航到 NestedScrollView 的所有元素。但是我无法到达 CollapsingToolbarLayout 内工具栏上的任何按钮。它有一个收藏夹按钮和一个选项菜单 - 溢出图标和我总是在应用栏上显示的 1。我如何到达这些图标?

这是活动2的布局

<?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"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/root_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <android.support.design.widget.AppBarLayout
            android:id="@+id/detail_app_bar_layout"
            android:layout_width="match_parent"
            android:layout_height="@dimen/place_detail_appbar_height"
            android:elevation="@dimen/place_detail_appbarlayout_elevation">
            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/detail_collapsing_toolbar_layout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@color/colorPrimary"
                android:transitionGroup="false"
                app:collapsedTitleGravity="start"
                app:collapsedTitleTextAppearance="@style/TextAppearance.AppCompat.Widget.ActionBar.Title.Inverse"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="72dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:id="@+id/detail_app_bar_photo"
                    android:layout_height="match_parent"
                    android:layout_gravity="center"
                    android:scaleType="centerCrop"
                    app:layout_collapseMode="parallax"
                    android:background="@color/colorPrimary"
                    android:contentDescription="@string/place_image"
                    android:transitionName="@string/shared_photo"
                    style="@style/ToolbarImage"/>

                <android.support.v7.widget.Toolbar
                    android:id="@+id/detail_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="@dimen/place_detail_toolbar_height"
                    android:background="@color/colorAccent"
                    app:layout_collapseMode="pin"
                    android:layout_gravity="bottom" …
Run Code Online (Sandbox Code Playgroud)

android navigation-drawer android-collapsingtoolbarlayout android-appbarlayout android-accessibility

8
推荐指数
3
解决办法
5091
查看次数