如何在NestedScrollView中显示滚动条 [英] How to show the Scrollbar in a NestedScrollView

查看:1220
本文介绍了如何在NestedScrollView中显示滚动条的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,我在Activity中实现了NestedScrollView,但是我不能像在ScrollView中一样显示滚动条,

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

我怎么显示它?

<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_scrolling_view_behavior",然后,我创建了一种样式,以在所有需要的NestedScrollViews中显示滚动条它.

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.

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>

在布局中:

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

这篇关于如何在NestedScrollView中显示滚动条的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆