标签: android-nestedscrollview

是否可以将ScrollView添加到AppBarLayout

我需要和两个人一起工作ScrollView.一个在里面AppBarLayout,另一个在外面.

对于外界ScrollView,我使用的是NestedScrollViewappbar_scrolling_view_behavior它的工作正常.

对于里面,我使用的是Scrollviewapp:layout_scrollFlags="scroll|enterAlways|snap"

我的问题是,NestedScrollView似乎覆盖了ScrollView事件,即使我触摸该ScrollView区域,NestedScrollView也就是滚动的事件.

有什么办法可以吗?

请参阅以下代码:

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

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:background="@android:color/white"
            app:layout_scrollFlags="scroll|enterAlways|snap">

            <TextView                
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>  

        </ScrollView>       
     </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">

        <TextView                
               android:layout_width="match_parent"
               android:layout_height="wrap_content"/>   

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

android android-scrollview android-coordinatorlayout android-nestedscrollview

5
推荐指数
1
解决办法
1821
查看次数

未针对CoordinatorLayout行为触发onNestedFling或onNestedPreFling

向上弹动时,不会为CoordinatorLayout中的NestedScrollView触发onNestedFling或onNestedPreFling行为回调。但是,当我向下飞行时,它们会被触发。任何已知问题?

当我用RecyclerView替换NestedScrollView时,会触发上述回调。

只是为了澄清,自定义行为类是:

public class DummyBehavior extends CoordinatorLayout.Behavior<View> {
    public DummyBehavior() {
    }

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

    @Override
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child, View directTargetChild, View target, int nestedScrollAxes) {
        Log.i("onStartNestedScroll", "true");
        return true;
    }

    @Override
    public boolean onNestedPreFling(CoordinatorLayout coordinatorLayout, View child, View target, float velocityX, float velocityY) {
        Log.i("onNestedPreFling", "true");
        return super.onNestedPreFling(coordinatorLayout, child, target, velocityX, velocityY);
    }

    @Override
    public boolean onNestedFling(CoordinatorLayout coordinatorLayout, View child, View target, float velocityX, float velocityY, boolean consumed) { …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-coordinatorlayout android-nestedscrollview

5
推荐指数
0
解决办法
1209
查看次数

导航栏隐藏的 NestedScrollView 底部 [Android]

NestedScrollView在布局上遇到了问题CollapsingToolbarLayout。当我将文本滚动到底部时,导航栏覆盖了最后一句。

在此处输入图片说明
布局.xml:

 <?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: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="250dp"
        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"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleTextAppearance="@style/ExpandedAppBar"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:title="Title">

            <ImageView
                android:id="@+id/toolbar_image_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:scaleType="centerCrop"
                android:src="@drawable/visit_at_office"
                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" />

        </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:fitsSystemWindows="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="@string/lorem_ipsum" />
    </android.support.v4.widget.NestedScrollView>
    </android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

向 TextView 添加边距底部修复了这个错误,但我想知道任何更好的解决方案以及为什么会发生这种情况。请问有人可以帮我吗?

android android-collapsingtoolbarlayout android-nestedscrollview

5
推荐指数
2
解决办法
2089
查看次数

Recyclerview scrollToPosition 不适用于 NestedScrollView ?有吗?

所以我有Recyclerview一个NestedScrollView. 当我说recycleview.scrollToPosition(X)或者recycleview.getLayoutManager().scrollToPosition(X)它根本不起作用时。

如果我recycleviewnestedScrollView它移出它工作正常,但我不能这样做,因为布局结构!任何的想法?

scrollingView.requestChildFocus(recyclerView,recyclerView);
Run Code Online (Sandbox Code Playgroud)

尝试过这个,但没有专注于某个位置

android android-scrollview android-recyclerview nestedscrollview android-nestedscrollview

5
推荐指数
1
解决办法
2973
查看次数

如何在Android中为NestedScrollView设置最大高度?

我有NestedScrollView一个ScrollView。在NestedScrollView包含TextView。因此,当TextView展开超过4或n个 lineas时,我需要制作它Scrollable TextView

任何帮助深表感谢!!

android textview android-nestedscrollview

5
推荐指数
1
解决办法
1081
查看次数

Android:为什么在NestedScrollView内部的RecyclerView底部有一个空白区域?

使用RecyclerViewinside 会在NestedScrollView中创建一个奇怪的空白空间(如底部填充)activity,导致不必要的滚动,因为没有更多元素要显示。

这个填充随着 增长RecyclerView,我的意思是:

如果其中RecyclerView有 0 到 2 个元素,这在屏幕上非常适合,并且没有滚动。这里运作良好。

如果RecyclerView有 3 到 5 个元素,这些元素继续适合屏幕,但在这种情况下会有更多的空白空间导致不必要的滚动。

随着更多元素,空白空间继续增长并产生越来越多的滚动。

这是我的 XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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.ibosca.thub.ChannelProfileActivity">

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

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">


        <de.hdodenhof.circleimageview.CircleImageView xmlns:app="http://schemas.android.com/apk/res-auto"
            android:id="@+id/channelPicture"
            android:layout_width="90dp"
            android:layout_height="90dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            app:civ_border_color="#FF000000"
            app:civ_border_width="2dp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.0"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:layout_constraintVertical_bias="0.0" />

        <TextView
            android:id="@+id/channelName"
            android:layout_width="256dp"
            android:layout_height="90dp"
            android:layout_marginBottom="8dp"
            android:layout_marginEnd="16dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:gravity="center_vertical"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:textAlignment="center"
            android:textColor="@android:color/black"
            android:textSize="20sp"
            android:textStyle="bold"
            app:layout_constraintBottom_toBottomOf="parent" …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-recyclerview android-nestedscrollview

5
推荐指数
1
解决办法
1387
查看次数

折叠 AppBarLayout 不使用 TabLayout 和 NestedScrollView 滚动

我在滚动折叠 AppBar 时遇到问题,当我尝试滚动它触摸 AppBarLayout 部分时。而且它有时滚动不顺畅。

这是问题的简短(1 米 30 秒)视频https : //www.youtube.com/watch?v=n32N9Z4S3SA&feature=youtu.be

这是简单项目的链接(仅在 github 上有此问题): https : //github.com/yozhik/Reviews/tree/master/app/src/main/java/com/ylet/sr/review

我正在使用:com.android.support : appcompat-v7 : 27.1.1

异地存在问题:https : //issuetracker.google.com/issues/37050152

情况如何:https : //www.youtube.com/watch?v=xWadOVEATSY&feature=youtu.be

应该如何:https : //www.youtube.com/watch?v=J8ITp6RusZo&feature=youtu.be

有人知道如何解决您在视频中看到的这个问题吗?我创建了绝对简单的布局以避免任何副作用,但错误仍然重现。提前致谢。

描述:

CollapsingActivity- 活动与Collapsing AppBarLayout。它将一两个片段加载到“ fragment_content_holder”中,并且必须TabLayout 在视图寻呼机中的片段之间切换。

在活动方法中onCreate()- 我只是模拟对服务器 ( loadData) 的请求,并且当加载了一些假数据时 - 我在第一次调用时在视图寻呼机中显示片段 - 我正在创建新的TabMenuAdapter扩展FragmentPagerAdapter,用片段填充它并将链接保存到实例. 在下一次调用中 - 我不会从头开始创建片段,而只是用新数据填充它们。

MenuFragment1, MenuFragment1- 两个碎片。 MenuFragment1- 具有 public void 方法setupData(SomeCustomData data) …

android android-fragments android-collapsingtoolbarlayout android-appbarlayout android-nestedscrollview

5
推荐指数
1
解决办法
1531
查看次数

同一滚动下的水平和垂直 RecyclerView

我必须做一些像 Instagram 那样的事情。我有一个用于故事的水平 RecyclerView,下面是一个用于提要的垂直 RecyclerView。我想完成相同的滚动行为(故事应该在滚动时与提要一起进行,而不是固定在顶部)。我找到的唯一解决方案是 NestedScrollView 但它使 RecyclerViews 的性能极其糟糕,我的屏幕几乎永远冻结。我尝试了很多在这里找到的技巧,如nestedScrollEnabled、autoLayoutMeasure 等,但没有任何效果。谢谢。

android android-scrollview instagram android-recyclerview android-nestedscrollview

5
推荐指数
1
解决办法
3050
查看次数

NestedScrollView 中的 RecyclerView 导致加载缓慢和/或崩溃

我正在使用 RecyclerView,它将用于加载潜在的许多图像,我希望在 RecyclerView 上方有一个操作栏,如下所示:

在此处输入图片说明

但我也希望操作栏的顶部只有灰色背景。如果用户滚动,它应该像这样完全透明:

在此处输入图片说明

通过使用它作为我的布局(有一个主要问题),我已经完成了我想要的:

fragment_recycler_gallery.xml

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

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

    <!-- Gray bar at top -->
    <View
        android:id="@+id/gray_bar"
        android:layout_width="match_parent"
        android:layout_height="50dp"
        android:background="@null" />

    <android.support.v7.widget.RecyclerView 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/recycler_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)

NestedScrollView 是让我的整个片段滚动而不仅仅是 RecyclerView 的关键,但它使我的应用程序在加载大量图像(500+)时变慢或无响应。有没有更好的方法来创建我正在寻找的东西?我试过寻找解决方案,但我能找到的只是“不要在nestedScrollViews中使用recyclerviews”,而没有提供任何替代解决方案。

如果这也很重要,我正在使用 Glide 将图像加载到每个 ImageView(在 recyclerview 内)中。

而且我已经在我的 RecyclerView 上使用了它:

mAlbumRecyclerView.setNestedScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)

android android-view android-recyclerview android-nestedscrollview

5
推荐指数
1
解决办法
2826
查看次数

CoordinatorLayout - 向相反方向投掷会导致抖动

我需要在顶部制作一个带有静态视图的可滚动片段,并在底部的每个页面中制作一个带有 RecyclerView 的 ViewPager。我正在尝试使用 CoordinatorLayout 来实现预期的结果,但遇到了一个问题 -当我向上翻转顶部视图(为了向下滚动)并且在向下翻转 RecyclerView 之后(为了向上滚动),滚动是好的抵消和抖动;当我第一次将 Recycler View 向下翻转然后将顶部视图向上翻转时,整个片段会滚动回顶部。当我开始向相反方向滚动时,滚动看起来像是继续而不是停止。

我找到了一个具有类似布局(code的教程,但是在尝试之后,我发现它遇到了同样的问题。

以下是问题记录:

编辑:在下面添加了布局代码

fragment_layout.xml

<?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: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.design.widget.CollapsingToolbarLayout
        android:id="@+id/main.collapsing"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        app:expandedTitleMarginStart="48dp"
        app:expandedTitleMarginEnd="64dp"
        app:layout_scrollFlags="scroll|snap"
        >
        ?
        <ImageView
            android:id="@+id/materialup.profile_backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="centerCrop"
            android:src="@drawable/picture300x300"
            app:layout_collapseMode="parallax"
            />
    </android.support.design.widget.CollapsingToolbarLayout>
    ??
    <android.support.v7.widget.Toolbar
        android:id="@+id/materialup.toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:minHeight="24dp"
        app:theme="@style/ThemeOverlay.AppCompat.Light"
        app:layout_scrollFlags="scroll|enterAlways|snap"
        style="@style/Widget.AppCompat.Toolbar"
        />
    ?
    <LinearLayout
        android:id="@+id/materialup.title_container"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:paddingTop="8dp"
        android:gravity="center" …
Run Code Online (Sandbox Code Playgroud)

android android-scrollview coordinator-layout android-coordinatorlayout android-nestedscrollview

5
推荐指数
1
解决办法
350
查看次数