android - 在 NestedScrollView (Android Studio) 中启用中间滚动

标签 android scrollview android-coordinatorlayout nestedscrollview

我有一个 NestedScrollView(默认滚动 Activity 的一部分),它包含一个 CoordinatorLayout 和 RecyclerView 来显示带有一些信息的卡片。布局旨在允许卡片在太多时离开屏幕并让用户向下滚动到它们,但是由于某种原因,滚动没有像它应该的那样有动力。我环顾四周,之前的一个问题告诉我如何在 ScrollView ( Android ScrollView disable Inertial scrolling ) 中禁用中间滚动,所以我尝试做相反的事情:

NestedScrollView mgScrollView = (NestedScrollView) findViewById(R.id.my_games_scroll_view);
mgScrollView.setSmoothScrollingEnabled(true);

但这并没有实现。我测试了 mgScrollView.setVerticalScrollBarEnabled(true);看看我是否将代码应用于正确的 View ,结果滚动条也没有出现。所以现在我很困惑我是否甚至将这些方法应用于正确的 View ,但由于我没有任何其他 ScrollViews 我不确定如果我不正确它应该在哪里。我知道我可以在 xml 本身中添加滚动条,但我还没有找到用于惯性滚动的 xml 代码。有没有办法通过java或者xml来增加惯性?

这是 content_my_games.xml 的代码,这是卡片布局的位置(不要与 activity_my_games.xml 混淆,后者包含 CollapsingToolbarLayout 和 FAB 的代码)

谢谢

<?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"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/my_games_scroll_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.abhinav.sportswowandroid.MyGamesActivity"
tools:showIn="@layout/activity_my_games">

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:paddingLeft="16dp"
    android:paddingRight="16dp"
    android:paddingTop="16dp"
    android:paddingBottom="16dp"
    tools:context=".MyGamesActivity">

    <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:fitsSystemWindows="true"
            tools:context=".MyGamesActivity"
            />

    <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
           app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior"
            />

    <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
    </RelativeLayout>
</android.support.v4.widget.NestedScrollView>

最佳答案

老问题,但我自己也遇到了这个问题。这为我解决了:

RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recycler_view);
recyclerView.setNestedScrollingEnabled(false);

关于android - 在 NestedScrollView (Android Studio) 中启用中间滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38298264/

相关文章:

android - Azure Cosmos DB - 错误请求 - http :400

java - 当我在 Android java 文件中使用 Fragment,Tabspager 时出现错误

android - 如何在 coordinatorLayout 中垂直放置布局

swift - 我的 ScrollView 中只有 2 页正在加载

android - CoordinatorLayout 末尾的 float 操作按钮

android - CollapsingToolbarLayout 内的 ImageView 在某些设备上不可见

android - 如何在android中获得ClusterManager点击和ClusterManager项目点击

android - 如何在 Android 3.0 上显示菜单按钮?

java - TableLayout 内的 ScrollView

android - 使编辑文本出现在android中设备的顶部和软键盘之间