Android 如何在NestedScrollView中显示滚动条

Android 如何在NestedScrollView中显示滚动条,android,mobile,scrollbar,scrollview,nestedscrollview,Android,Mobile,Scrollbar,Scrollview,Nestedscrollview,嘿,我在一个活动中实现了NestedScrollView,但我不能像在ScrollView中那样显示滚动条,你们可以吗 我怎样才能展示它 <android.support.v4.widget.NestedScrollView android:layout_width="match_parent" android:layout_height="match_parent" android:layout_below="@+id/appBar">

嘿,我在一个活动中实现了NestedScrollView,但我不能像在ScrollView中那样显示滚动条,你们可以吗

我怎样才能展示它

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

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:orientation="vertical"
            android:paddingLeft="@dimen/dimen_2"
            android:paddingRight="@dimen/dimen_2">
        </LinearLayout>
</android.support.v4.widget.NestedScrollView>

我找到了解决方案,首先将NestedScrollView行为设置为“@string/appbar\u scrolling\u view\u behavior”,然后,我创建了一个样式,在我需要的所有NestedScrollView中显示滚动条

styles.xml
中:

<resources>
    <!-- other styles -->

    <style name="NestedScrollBarStyle">
        <item name="android:scrollbarFadeDuration">2</item>
        <item name="android:scrollbars">vertical</item>
        <item name="android:fillViewport">true</item>
        <item name="android:orientation">vertical</item>
    </style>
</resources>

2.
垂直的
真的
垂直的
在布局中:

<android.support.v4.widget.NestedScrollView
    style="@style/NestedScrollBarStyle"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/appBar"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clipChildren="false"
        android:clipToPadding="false"
        android:orientation="vertical"
        android:paddingLeft="@dimen/dimen_2"
        android:paddingRight="@dimen/dimen_2">
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

使用android:scrollbars属性

例如:

android:scrollbars="vertical"

android:scrollbars="horizontal"

android:scrollbars="vertical|horizontal"
例如:

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

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

你已经知道答案了,你同时写下了问题和答案。请不要这样做@事实上,在stackoverflow中发布一个问题和答案是很好的。毕竟,stackoverflow的目标是让开发人员能够找到问题的答案。谁提供答案并不重要,只要答案是正确的。@Ridcully谢谢。这些天我很天真。我还是有时候,对不起。谢谢,两句话:1。您认为2毫秒是
scrollbarFadeDuration
的良好默认值吗?Android 6.0上的ScrollView使用250毫秒(确认
Log.d(标记“+”(新的ScrollView(this)).getScrollBarFadeDuration();
)。2.你真的需要设置应用程序:布局行为吗?在我的测试中,这个设置是不相关的。我还可以确认app:layout_behavior属性对此不是必需的,250ms是一个更自然的感觉消退持续时间。请参阅我的答案以获得更简单的解决方案。