标签: nestedscrollview

NestedScrollView和Horizo​​ntal RecyclerView平滑滚动

我有一个垂直的nestedscrollview,其中包含一堆带有水平布局管理器设置的recyclerview.这个想法非常类似于新的谷歌游戏商店的外观.我能够使它起作用,但它根本不光滑.以下是问题:

1)水平回收视图项目大多数时间都无法拦截触摸事件,即使我点击它也是如此.滚动视图似乎优先于大多数动作.我很难在水平运动上找到钩子.这个用户体验令人沮丧,因为我需要在它工作之前尝试几次.如果你检查游戏商店,它能够很好地拦截触摸事件,它只是运作良好.我注意到在游戏商店中他们设置的方式是在一个垂直的回收者视图中的许多水平回收视图.没有滚动视图.

2)水平回收视图的高度必须手动设置,并且没有简单的方法来计算子元素的高度.

这是我正在使用的布局:

<android.support.v4.widget.NestedScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipToPadding="false"
    android:background="@color/dark_bgd"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <LinearLayout
            android:id="@+id/main_content_container"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            tools:visibility="gone"
            android:orientation="vertical">                

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/starring_list"
                    android:paddingLeft="@dimen/spacing_major"
                    android:paddingRight="@dimen/spacing_major"
                    android:layout_width="match_parent"
                    android:layout_height="180dp" />
Run Code Online (Sandbox Code Playgroud)

此UI模式非常基本,很可能在许多不同的应用程序中使用.我已经阅读了许多SO,其中ppl说将列表放在列表中是一个坏主意,但它是一个非常普遍和现代的UI模式在整个地方使用.想看netflix就像界面里面有一系列水平滚动列表垂直清单.有没有一个顺利的方法来实现这一目标?

来自商店的示例图片:

Google Play商店

android horizontal-scrolling android-recyclerview nestedscrollview

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

NestedScrollView阻止Nougat上的bug(API 25)

我在Nexus 5x(7.1.2)和Google Pixel(7.1.1)上使用NestedScrollView时遇到了一个奇怪的问题.在其他操作系统版本上它运行正常.

举起动画有时会在举起手指后立即停止.它会停滞不前,接下来的几次飞行也可能会停止.为了重现它,你需要上下几次投掷.

在日志中,这些flings在速度,方向等方面看起来几乎相同,所以我找不到这个bug的真正原因.

NestedScrollView并不一定需要的内部CoordinatorLayout,也可以没有NestedScrollingChild在所有.

例如,此错误可以使用以下NestedScrollView子项之一重现:

1)LinearLayout填充TextViews

2) WebView

3)LinearLayout填充RecyclerViews.

我知道RecyclerView内部和行为的可能问题CoordinatorLayout,但它没有关系.所以请不要提及任何

recyclerView.getLayoutManager().setAutoMeasureEnabled(true);
recyclerView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)

或类似的东西.

代码示例:

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

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

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:text="Put a super long text here"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="16dp"
            android:text="Put a super long text here"/>

    </LinearLayout>

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

android scroll android-support-library nestedscrollview android-7.0-nougat

18
推荐指数
1
解决办法
2094
查看次数

NestedScroll与NestedScrollView,RecyclerView(水平),在CoordinatorLayout内

我有一个使用CollapsingToolbarLayout的UI设计,如下所示.

<android.support.design.widget.AppBarLayout
    android:id="@+id/appbar"
    android:layout_width="match_parent"
    android:layout_height="@dimen/detail_backdrop_height"
    android:fitsSystemWindows="true"
    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">

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fitsSystemWindows="true"
            android:scaleType="centerCrop"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:layout_collapseMode="pin"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

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

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

<android.support.v4.widget.NestedScrollView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:fillViewport="true"
    android:theme="@style/ThemeOverlay.AppCompat.Light"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="24dp">

        <!-- Hiding unrelated code -->

        <android.support.v7.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="@dimen/card_margin"
            android:padding="16dp">


                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recycler_movie_suggestion"
                    android:layout_width="match_parent"
                    android:layout_height="170dp"
                    android:fillViewport="true"
                    android:nestedScrollingEnabled="false"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior" />

            </LinearLayout>

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

    </LinearLayout>

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

我的问题是,只有当我触摸并滚动RecyclerView外面的区域时滚动才能正常.如果我尝试在RecyclerView内部垂直滚动,则滚动"陷阱"并且只有NestedScrollView滚动,CollaspingToolbarLayout不会重叠.

android android-recyclerview coordinator-layout nestedscrollview

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

在NestedScrollView中平滑滚动到Child

我在CardView父母的内部有可扩展的视图NestedScrollView.当扩展动画结束时,我正在尝试为子项创建平滑滚动.但我发现只有一个解决方案:

 scrollView.requestChildFocus(someView, someView);
Run Code Online (Sandbox Code Playgroud)

这段代码工作正常,但是,当requestChildFocus它调用时它立即滚动,这让我很烦恼.是否可以顺利滚动到孩子?

android nestedscrollview

13
推荐指数
2
解决办法
7616
查看次数

与CollapsingToolbarLayout一起使用时,NestedScrollView不会滚动到结尾

我想将NestedScrollView与CollapsingToolbarLayout一起使用.在NestedScrollView中,内容确实很长.不幸的是我无法滚动到最后.一些长期内容被削减.当我转动屏幕,滚动工作正常并且所有内容都可见时,有什么奇怪的.

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

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

        <android.support.design.widget.CollapsingToolbarLayout
            android:fitsSystemWindows="true"
            android:layout_height="match_parent"
            android:layout_width="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:fitsSystemWindows="true"
                android:layout_height="wrap_content"
                android:layout_width="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/u8"
                app:layout_collapseMode="parallax"/>

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

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

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

    <android.support.v4.widget.NestedScrollView
        android:clipToPadding="false"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

            <!-- lots of widgets-->

        </LinearLayout>

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

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

编辑:我注意到切割内容的高度与工具栏高度相同.

layout android android-collapsingtoolbarlayout android-appbarlayout nestedscrollview

13
推荐指数
3
解决办法
5942
查看次数

使用AppBarLayout.Behavior使用NestedScrollView顺利运行AppBarLayout

我有一个AppBarLayout和NestedScrollView.我想要NestedScrollView,只要它向下滚动,AppBarLayout也应该正常展开,而不会在AppBarLayout展开之前停止NestedScrollView; 完成第二次飞行/滚动需要完成.

我检查stackoverflow,发现这个解决方案非常相关,可以使用.但是如果是NestedScrollView,那就是RecyclerView.它位于/sf/answers/2271808521/

我基本上拿了代码并稍微改了一下,并用来检查速度> 8000以考虑将AppBarLayout作为下面的代码.

public final class FlingBehavior extends AppBarLayout.Behavior {
    private boolean isPositive;

    public FlingBehavior() {
    }

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

    @Override
    public boolean onNestedFling(CoordinatorLayout coordinatorLayout, AppBarLayout child, View target, float velocityX, float velocityY, boolean consumed) {
        if (velocityY > 0 && !isPositive || velocityY < 0 && isPositive) {
            velocityY = velocityY * -1;
        }

        if (target instanceof NestedScrollView && Math.abs(velocityY) > 8000) {
            consumed = false;
        }
        return super.onNestedFling(coordinatorLayout, child, …
Run Code Online (Sandbox Code Playgroud)

android android-appbarlayout nestedscrollview android-nestedscrollview

13
推荐指数
1
解决办法
4689
查看次数

FrameLayout与NestedScrollView的高度不匹配

我在NestedScrollView中有一个FrameLayout,如

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

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#000000">
Run Code Online (Sandbox Code Playgroud)

但是FrameLayout没有填充NestedScrollView的高度.我该如何解决这个问题?

android android-layout nestedscrollview android-framelayout

11
推荐指数
1
解决办法
4395
查看次数

在NestedScrollView Android 2.3或更低版本中滚动WebView

我添加了Toolbar,TablayoutViewpager在我的Android应用程序中.有三个TabsTabLayout,每个显示WebView.我把它WebView放在一个NestedScrollView隐藏/显示Toolbar用户向下/向上滚动的位置WebView.Toolbar隐藏在Android 3.0或更高版本中.但不幸的是,在Android 2.3或更低版本WebView中,首先不会滚动.我必须刷到另一个Tab,当我Tab再次回到First 时WebView开始滚动.

我想要的是?

我希望它WebView应该滚动Android 2.3或更少没有任何问题.

我的WebView

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <LinearLayout
            xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical"
            android:paddingTop="1dp">

     <WebView
         android:id="@+id/webviewtool"
         android:layout_width="match_parent"
         android:layout_height="fill_parent"
         android:numColumns="1"
         android:scrollbars="none"
         android:focusableInTouchMode="false"
         android:focusable="false"
         android:background="#FFFFFF" />

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

android toolbar webview android-viewpager nestedscrollview

10
推荐指数
1
解决办法
1135
查看次数

如果ListView在NestedScrollView中,match_parent不适用于ListView

在我的应用程序中,我正在使用它ListView,它在一个内部NestedScrollView.当我设置heightListView,以match_parent不覆盖整个屏幕.我想要ListView覆盖整个屏幕.

我的XML文件:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:isScrollContainer="false"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="fill_vertical"
        android:clipToPadding="false"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

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

        <ListView
            android:id="@+id/list"
            android:layout_width="fill_parent"
            android:layout_height="match_parent"
            android:divider="@null" />
        </LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

xml android listview nestedscrollview

10
推荐指数
2
解决办法
6032
查看次数

android - CoordinatorLayout/NestedScrollView /隐藏 - 显示工具栏/ WebView问题

我有一个问题:

<?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"
    android:id="@+id/coordinatorLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

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

        <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" />
    </android.support.design.widget.AppBarLayout>

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

        <WebView
            android:id="@+id/webView"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </android.support.v4.widget.NestedScrollView>

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

当我在webview中滚动时,工具栏被隐藏或显示(完美!)但是加载/定位网页时出现问题.例如,如果我滚动到页面的中间并单击链接,则将加载的新页面也位于页面的大约中间而不是顶部.好像滚动条没有从一个页面移动到另一个页面.

如果我添加到NestedScrollView:

android:fillViewport="true"
Run Code Online (Sandbox Code Playgroud)

一切都适用于webview(页面加载并显示良好,虽然从顶部开始)但我丢失隐藏/显示与工具栏:(

你对这个问题有什么看法吗?

预先感谢您的帮助 :)

(有关信息:Android设计支持库:23.0.1)

android toolbar webview nestedscrollview

10
推荐指数
1
解决办法
3561
查看次数