How to show the Scrollbar in a NestedScrollView

后端 未结 2 687
醉酒成梦
醉酒成梦 2021-02-08 04:33

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?



        
相关标签:
2条回答
  • 2021-02-08 04:49

    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>
    
    0 讨论(0)
  • 2021-02-08 05:00

    Use the android:scrollbars attribute.

    Such as:

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

    For example:

    <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

    0 讨论(0)
提交回复
热议问题