标签: android-nestedscrollview

OnNestedScroll - 有时不触发

当我滚动NestedScrollViewCoordinatorLayout. 我实现了这一点Behavior,您可以通过此链接进行检查(github示例)。问题是在OnNestedScroll方法内部调用显示/隐藏方法。不幸的是,有时当我滚动时,不会调用此方法。然而,onNestedScrollAccepted方法总是被调用。我没有找到任何不调用它的原因(比如 20-30% 的时间)。你知道为什么会发生这种情况吗?

这是我的行为课:

public class ScrollAwareFABBehavior  extends CoordinatorLayout.Behavior {
    FloatingActionMenu fabMenu;
    Context cont;

    public ScrollAwareFABBehavior(Context context, AttributeSet attrs) {
        super();
        cont =context;
    }
    @Override
    public boolean onStartNestedScroll(CoordinatorLayout coordinatorLayout, View child,
                                       View directTargetChild, View target, int nestedScrollAxes) {
        if (nestedScrollAxes == ViewCompat.SCROLL_AXIS_VERTICAL)
        {
            return true;
        }
        return super.onStartNestedScroll(coordinatorLayout, child, directTargetChild, target,
                        nestedScrollAxes);
    }

    @Override
    public void onNestedScroll(CoordinatorLayout coordinatorLayout, View child, View target,
                               int dxConsumed, int dyConsumed, int …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-coordinatorlayout android-nestedscrollview

6
推荐指数
0
解决办法
1045
查看次数

将触摸事件从 NestedScrollView 传递给父视图

我在 NestedScrollView 宽度下方有一个 ViewPager 一些顶部填充,以及 clipToPadding(false) 和透明背景(如图像)。

我的 ViewPager 无法获得触摸事件并且不起作用。

我怎么解决这个问题?

(我不能改变我的结构,也不能将 ViewPager 移动到 NestedScrollView 的上方或将 TopMargin 设置为 NestedScrollView)

ViewPager 在一个透明的 NestedScrollView 下面

ViewPager 在一个透明的 NestedScrollView 下面

嵌套滚动视图

nestedScrollView = new NestedScrollView(getContext());
nestedScrollView.setFillViewport(true);
nestedScrollView.setLayoutParams(scrollParams);
nestedScrollView.setClipToPadding(false);
Run Code Online (Sandbox Code Playgroud)

解决方案:

通过覆盖 NestedScrollView 和 Override onTouchEvent 解决了这个问题。(感谢@petrumo

public class MyNestedScrollView extends NestedScrollView {
    private boolean topZone = false;

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

    @Override
    public boolean onTouchEvent(MotionEvent ev) {
        if(ev.getAction() == MotionEvent.ACTION_DOWN ){
            topZone = (getPaddingTop() - getScrollY() >  ev.getY());
        }

        if(topZone){
            if(ev.getAction() == MotionEvent.ACTION_UP){
                topZone = false;
            }
            return …
Run Code Online (Sandbox Code Playgroud)

android touch-event android-viewpager android-nestedscrollview

6
推荐指数
1
解决办法
4071
查看次数

NestedScrollView 使用nestedScrollEnabaled 属性时抛出错误“android.view.InflateException”

我在NestedScrollView 中ViewPager,为了让我的ViewPager附加正确的高度和滚动属性,我添加到我的NestedScroll..,这是我的设计的一个快照:android:nestedScrollingEnabled="true"

    <?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"
    xmlns:tools="http://schemas.android.com/tools"
    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">

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

    <android.support.v4.widget.NestedScrollView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:id="@+id/nestedScroll"
        android:nestedScrollingEnabled="true"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewPager"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="@dimen/_7sdp"
            android:layout_marginRight="@dimen/_7sdp"/>
    </android.support.v4.widget.NestedScrollView>


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

问题:当我设置android:nestedScrollingEnabled="true"为 true 时,我得到了这些异常:

java.lang.RuntimeException: Unable to start activity ComponentInfo{somePackege}: android.view.InflateException: Binary XML file line #0: Binary XML file line #0: Error inflating class <unknown>
Run Code Online (Sandbox Code Playgroud)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.support.v4.view.NestedScrollingChildHelper.setNestedScrollingEnabled(boolean)' on …
Run Code Online (Sandbox Code Playgroud)

android android-viewpager android-coordinatorlayout android-nestedscrollview

6
推荐指数
1
解决办法
5243
查看次数

NestedScrollView内ViewPager内的NestedScrollView:最内层的NestedScrollView不滚动

所以我有一个使用CoordinatorLayout并带有NestedScrollView的Fragment。在NestedScrollView的内部是ViewPager。该ViewPager的每个项目都是一个内部带有NestedScrollView的CoordinatorLayout。

我想要的行为是,当上下滚动ViewPager中的每个项目时,我的自定义BottomBar将消失并重新出现。

但是,当我上下滚动时,BottomBar消失并重新出现,但是最里面的ScrollView中的内容不会移动。这就是问题

下面发布了代码,任何建议都将有所帮助。

我尝试过的事情:

  1. 在层次结构中几乎可以滚动的每个视图上调用ViewCompat.setNestedScrollingEnabled()。
  2. 在最外面的NestedScrollView上调用requestDisallowInterceptTouchEvent(true)。

主要活动: 在此处输入图片说明

带外部NestedScrollView的片段: 在此处输入图片说明

ViewPager中的每个项目: 在此处输入图片说明

android android-viewpager android-coordinatorlayout android-nestedscrollview

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

滚动时为什么滚动在折叠工具栏处停止?(不扩展以显示图像)

正如我在标题上所解释的那样,如果我在向下拉动后立即从下往上快速滚动,在折叠的工具栏上滚动停止.我希望它能够扩展.如果我顺畅地拉动nestedscrollview,没有问题,工具栏会正确扩展.我在nestedscrollview中有recycleler视图.这是我的布局

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/detail_content"
    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="160dp"
        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"
            android:theme="@style/ThemeOverlay.AppCompat.Dark"
            app:contentScrim="?attr/colorPrimary"
            app:expandedTitleMarginEnd="@dimen/article_keylines"
            app:expandedTitleMarginStart="@dimen/md_keylines"
            app:expandedTitleMarginBottom="@dimen/article_keylines"
            app:layout_scrollFlags="scroll|exitUntilCollapsed"
            app:expandedTitleTextAppearance="@dimen/tile_padding"
            >

            <ImageView
                android:id="@+id/image"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@drawable/a"
                android:fitsSystemWindows="true"
                android:foreground="@drawable/scrim_profile"
                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"
                android:elevation="4dp"
                app:layout_scrollFlags="scroll|enterAlways|snap"
                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="match_parent"
        android:id="@+id/nestedscrollview"
        android:background="@color/background"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        >

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            >
            <RelativeLayout
                android:id="@+id/inner_relativeLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/md_keylines"
                android:paddingRight="@dimen/md_keylines"
                android:background="@color/white"
                android:paddingBottom="@dimen/article_keylines"
                android:paddingTop="@dimen/article_keylines"
                android:focusableInTouchMode="true"
                >
                <TextView
                    android:id="@+id/tw1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textColor="@color/text"
                    android:textSize="16sp"
                    android:lineSpacingExtra="4sp"
                    android:text="Text"
                    android:layout_marginBottom="@dimen/md_keylines"/>

                <View …
Run Code Online (Sandbox Code Playgroud)

android scroll android-coordinatorlayout android-collapsingtoolbarlayout android-nestedscrollview

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

NestedScrollView剪切/覆盖嵌套片段的底部

我有问题NestedScrollView,因为它削减了视图的底部.

我有FragmentA架构:

<RelativeLayout>
<android.support.design.widget.CoordinatorLayout>
    <android.support.design.widget.AppBarLayout>
        <android.support.design.widget.CollapsingToolbarLayout>
            <ImageView/>
            <android.support.v7.widget.Toolbar/>
        </android.support.design.widget.CollapsingToolbarLayout>
    </android.support.design.widget.AppBarLayout>
    <android.support.v4.widget.NestedScrollView>
        <LinearLayout>
            <FrameLayout> 
                <!-- fragment added dynamically-->
            </FrameLayout>
            <FrameLayout>
                <!-- fragment added dynamically-->
            </FrameLayout>
            <FrameLayout>
                <!-- fragment added dynamically-->
            </FrameLayout>
        </LinearLayout>
    </android.support.v4.widget.NestedScrollView>
    <android.support.design.widget.FloatingActionButton/>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

我正在为每个添加dinamically片段FrameLayout.

当我第一次运行应用程序时,我做了SS的样子:我第一次在屏幕上 为每个布局添加填充以查看发生了什么. greenCoordinatorLayout, redNestedScrollView, orangeLinearLayout里面NestedScrollView.

现在我更换FragmentAFragmentB,并再次复出FragmentA,我有这样的事情:错误dispaly

有人知道我做错了什么?

这是我的整个布局FragmentA:

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

<android.support.design.widget.CoordinatorLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorP" …
Run Code Online (Sandbox Code Playgroud)

android android-fragments android-coordinatorlayout android-nestedscrollview

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

保存NestedScrollView的滚动状态

我的应用程序围绕一个HomeActivity,底部包含4个选项卡.这些选项卡中的每一个都是一个片段,所有这些片段都是从头开始添加(不替换),并且在点击相应的选项卡时隐藏/显示它们.

我的问题是每当我更改标签时,我的滚动状态都会丢失.展示该问题的每个片段使用a android.support.v4.widget.NestedScrollView(参见下面的示例).

注意:使用RecyclerView或ListView的片段由于某种原因保持其滚动状态.

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

    <include layout="@layout/include_appbar_title" />

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

        <!-- Content -->

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

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

我读了几篇关于保存实例状态的帖子(这个,例如那个),他们的解决方案要么在我的场景中不起作用,要么实际上不实用,因为我有4-12个不同的片段我需要修改使其工作.

使嵌套滚动视图在片段更改时保持滚动位置的最佳方法是什么?

android savestate android-nestedscrollview

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

如何在NestedScrollView中使用RecyclerView

我有这个布局:

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

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

            <--There is some layouts here-->
            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>
    </LinearLayout>

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

它运作良好.我可以RecyclerView平滑滚动而无需滚动父视图.

现在我必须把RecyclerView内部放在这样一个FrameLayout:

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

    <LinearLayout
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">
 <--There is some layouts here-->
        <FrameLayout
            android:id="@+id/review_layout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <RecyclerView
                android:id="@+id/recycler_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

            <include
                android:id="@+id/empty_view"
                layout="@layout/review_empty_view"
                android:visibility="gone" />
        </FrameLayout>
    </LinearLayout>

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

现在我无法RecyclerView顺利滚动.我想要的是:RecyclerView平滑滚动而不滚动父视图.我该怎么办?

编辑:这是我的review_empty布局:

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:orientation="horizontal"
    android:padding="16dp">

    <ImageView
        android:layout_width="80dp"
        android:layout_height="80dp"
        android:src="@drawable/shopping_review_empty" …
Run Code Online (Sandbox Code Playgroud)

android android-recyclerview android-nestedscrollview

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

在加载大量数据时,NestedScrollView中的RecyclerView需要花费太多时间

NestedScrollView中的RecyclerView在加载大量数据时会冻结Activity.使用ScrollView加载速度要快得多,但在这种情况下滚动会受到影响.我尝试设置像setAutoMeasure和setNestedScrollingEnabled这样的属性没有帮助.有什么建议?

android android-recyclerview android-nestedscrollview

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

如何在NestedScrollView中限制RecyclerView的高度

在我当前的Android应用程序中,我有一个显示的屏幕android.support.v4.app.DialogFragment.

DialogFragment视图包含以下UI组件

HEADING
== Sub Heading
== NestedScrollView
==== RecyclerView
==== RadioGroup
==== Spinner
==== EditText
==== Action Buttons
Run Code Online (Sandbox Code Playgroud)

DialogFragment被配置为使用样式如下全屏: -

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setStyle(DialogFragment.STYLE_NO_TITLE, R.style.AppDialogTheme);
}
Run Code Online (Sandbox Code Playgroud)

我的对话框风格是

<!-- Define your custom dialog theme here extending from base -->
<style name="AppDialogTheme" parent="Theme.AppCompat.Light.Dialog">
    <!-- Define color properties as desired -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">#000</item>
    <item name="android:textColorHighlight">@color/background_url</item>
    <item name="colorAccent">@color/dark_grey</item>
    <item name="colorControlNormal">@color/colorPrimaryDark</item>
    <!-- Define window properties as desired -->
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowFullscreen">true</item> …
Run Code Online (Sandbox Code Playgroud)

java android android-recyclerview android-nestedscrollview

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