How to show the Scrollbar in a NestedScrollView

做~自己de王妃 提交于 2019-12-09 11:05:56

问题


Hey i implemented a NestedScrollView in an Activity, but i cant show the scrollbar like i do in a ScrollView, can you guys.

How can I show it?

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

回答1:


Use the android:scrollbars attribute.

Such as:

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>

Documentation link: https://developer.android.com/reference/android/view/View.html#attr_android:scrollbars




回答2:


I found the solution, first set the NestedScrollView behaviour to "@string/appbar_scrolling_view_behavior" then, I created a style to show the scrollbars in all NestedScrollViews where I need it.

in 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>

in the layout:

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


来源:https://stackoverflow.com/questions/39687679/how-to-show-the-scrollbar-in-a-nestedscrollview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!