当内容填充时,NestedScrollView向下滚动

Ogn*_*air 51 android nestedscrollview

我有XML,这consits的DrawerLayout,CoordinatorLayoutcustom views,AppBarLayout,NestedScrollView.

问题:NestedtScrollView填充内容时,NestedtScrollView向下滚动.所有的研究,如scrollView.setScrollY(0)定制课程都layout_behavior = FixedScrollingViewBehavior没有帮助我.

我该如何阻止这种滚动

    <android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/drawer"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">


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

    <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="0dp"
            android:layout_weight="1">

        <android.support.design.widget.AppBarLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:fitsSystemWindows="true"
                android:background="@color/semitransparet_color_primary">

            <android.support.v7.widget.Toolbar
                    xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:app="http://schemas.android.com/apk/res-auto"
                    android:id="@+id/actionbar_toolbar"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_scrollFlags="scroll|enterAlways"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:elevation="4dp"/>

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

        <ProgressBar
                android:id="@+id/progress"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"/>
        <android.support.v4.widget.NestedScrollView
                android:id="@+id/product_scroll_wrpr"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:visibility="gone">

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

                // my content is here

            </LinearLayout>


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



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

    <LinearLayout
            android:id="@+id/buttons_bar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="gone"
            android:background="#01579B"
            android:layout_gravity="bottom"
            android:orientation="horizontal"
            android:padding="8dp"
            android:gravity="center_vertical">

    // here are my buttons

</LinearLayout>

<android.support.design.widget.NavigationView
        android:id="@+id/navi"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        android:background="@android:color/white"
        app:headerLayout="@layout/drawer_header_left"
        app:menu="@menu/nav_drawer_menu"/>
Run Code Online (Sandbox Code Playgroud)

我的build.gradle应付

compile 'com.android.support:support-v4:23.1.0'

compile 'com.android.support:design:23.0.1'
Run Code Online (Sandbox Code Playgroud)

Kon*_*pko 184

尝试设置android:descendantFocusability="blocksDescendants"LinearLayout里面NestedScrollView.这个对我有用.

UPD:谨防使用布局后代元素EditText,这应该是一个焦点:元素不会成为焦点.如果您知道如何解决这个问题,请告诉我们.

  • 也许你可以进一步解释一下,这会提高你的回答质量。 (2认同)
  • 如果您有任何带有android:textIsSelectable =“ true”的TextView元素,则会阻止文本选择。最好仅将父视图设置为可聚焦。 (2认同)

and*_*per 16

阻止焦点的另一种方法是添加一个可以窃取焦点的新视图.把它放在NestedScrollView上面的任何地方,它应该工作:

    <!--focusStealer, to avoid NestedScrollingView to scroll due to dynamically created views that take the focus-->
    <View
        android:layout_width="0px" android:layout_height="0px" android:focusable="true"
        android:focusableInTouchMode="true"/>
Run Code Online (Sandbox Code Playgroud)


Hit*_*pra 6

这对我有用:

mNestedScrollViewChat.post(new Runnable(){
    @Override
    public void run(){
        mNestedScrollViewChat.fullScroll(View.FOCUS_DOWN);
    }
});
Run Code Online (Sandbox Code Playgroud)