android - 填充内容时,NestedScrollView 会自行向下滚动

标签 android nestedscrollview

我有 xml,它由 DrawerLayoutCoordinatorLayoutcustom viewsAppBarLayout 组成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"/>

我的 build.gradle 构成

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

compile 'com.android.support:design:23.0.1'

最佳答案

尝试将 android:descendantFocusability="blocksDescendants" 设置为 NestedScrollView 内的 LinearLayout。它对我有用。

UPD: 谨防在布局中使用像 EditText 这样的后代元素,它应该获得焦点:这些元素不会获得焦点。如果您知道如何解决此问题,请告诉我们。

关于android - 填充内容时,NestedScrollView 会自行向下滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34419859/

相关文章:

android - 如何在不切断 View 的情况下使用 GridView/ListView 实现 SwipeRefreshLayout?

Android: "BadTokenException: Unable to add window; is your activity running?"在 PreferenceActivity 中显示对话框

android通知栏显示/隐藏切换

android - NestedScrollView Android 中的 RecyclerView

flutter - 自定义 ScrollView 在 Sliver Persistent Header 下滚动

android - 如果 nestedscrollview 结束,如何停用滚动父 ScrollView ?

Android - 一次动画边距/更改多个 View 的位置

android - 如果项目 View 中有 Button,则 onItemClick 不起作用