android ListView滚动条样式

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3103132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 08:42:09  来源:igfitidea点击:

android ListView scrollbarStyle

androidlistviewscrollbars

提问by Ben

Does anyone know of any documentation on the android:scrollbarStyle? I'd like to see examples of each of the 4 values w/ screenshots if possible. I see the difference between outside & inside types, but what are the Inset & Outset parts all about? I dont seem to see a difference between insideOutset & insideInset for example, likewise, I don't see a difference between outsideOutset & outsideOutset.

有谁知道关于 android:scrollbarStyle 的任何文档?如果可能,我想查看带有屏幕截图的 4 个值中的每一个的示例。我看到了外部和内部类型之间的区别,但是 Inset 和 Outset 部分是关于什么的?例如,我似乎没有看到 insideOutset 和 insideInset 之间的区别,同样,我没有看到 externalOutset 和 externalOutset 之间的区别。

thanks in advance! Ben

提前致谢!本

回答by Scott Stanchfield

Here's a little more detailed example. I set up background colors to make it more obvious what's going on here.

这里有一个更详细的例子。我设置了背景颜色,使这里发生的事情更加明显。

Android scrollBarStyle settings visualized

Android scrollBarStyle 设置可视化

First, the colors:

首先是颜色:

  • black - margins
  • white - padding
  • gray - the contents of the scrollview
  • green - the scrollbar ifit takes up its own space (I added this explicitly as a scrollbarTrackVerticalfor the two "inset" examples)
  • 黑边
  • 白色填充
  • 灰色 - 滚动视图的内容
  • 绿色 - 滚动条,如果它占据了自己的空间(我明确添加了它作为scrollbarTrackVertical两个“插图”示例的 a )

Let's define two sections:

让我们定义两个部分:

  • "content area" - the stuff to be displayed in the scroll view
  • "padding" - the space around the content of the scroll view
  • “内容区域” - 要在滚动视图中显示的内容
  • “padding” - 滚动视图内容周围的空间

Let's think about the two parts of the scrollBarStyleseparately:

让我们分别考虑一下两部分scrollBarStyle

  • inside- the scrollbar appears insidethe content area (the padding wraps around both the content and the scrollbar)

  • outside- the scrollbar appears outsidethe content area

  • overlay- the scrollbar overlays the right edge of the section it's in

  • inset- the scrollbar pushes the section it's in to the left, taking up its own space

  • inside- 滚动条出现内容区域内(内边距环绕内容和滚动条)

  • outside- 滚动条出现在内容区域之外

  • overlay- 滚动条覆盖它所在部分的右边缘

  • inset- 滚动条将它所在的部分向左推,占用自己的空间

The layout xml appears below

布局xml出现在下面

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000"
    >

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbarStyle="insideOverlay"
        android:background="#fff"
        android:fadeScrollbars="false"
        android:layout_margin="8dp"
        android:padding="16dp" >
            <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaa" >
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
                <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideOverlay"/>
            </LinearLayout>
    </ScrollView>

    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbarStyle="insideInset"
        android:background="#fff"
        android:scrollbarTrackVertical="@drawable/green_block"
        android:fadeScrollbars="false"
        android:layout_margin="8dp"
        android:padding="16dp" >

        <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaa" >
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="insideInset" />
        </LinearLayout>

    </ScrollView>
    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:scrollbarStyle="outsideOverlay"
        android:background="#fff"
        android:fadeScrollbars="false"
        android:layout_margin="8dp"
        android:padding="16dp" >

        <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaa" >
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideOverlay" />
        </LinearLayout>

    </ScrollView>
    <ScrollView 
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="#fff"
        android:layout_weight="1"
        android:scrollbarStyle="outsideInset"
            android:scrollbarTrackVertical="@drawable/green_block"
        android:fadeScrollbars="false"
        android:layout_margin="8dp"
        android:padding="16dp" >

        <LinearLayout android:orientation="vertical" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="#aaa" >
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
            <TextView android:textSize="32sp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="outsideInset" />
        </LinearLayout>
    </ScrollView>
</LinearLayout>

回答by Vijay C

There are no values like outsideOutset and insideOutset. Possible four values are insideOverlay, insideInset, outsideOverlay, outsideInset
the documentation is there at following two links...

没有像outsideOutset 和insideOutset 这样的值。可能的四个值是insideOverlay、insideInset、outsideOverlay、outsideInset
文档位于以下两个链接...

http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarStyle

http://developer.android.com/reference/android/view/View.html#attr_android:scrollbarStyle

http://developer.android.com/reference/android/view/View.html#SCROLLBARS_INSIDE_INSET

http://developer.android.com/reference/android/view/View.html#SCROLLBARS_INSIDE_INSET

I couldn't understand the documentation properly. So taking reference from ApiDemos Scrollbar demo, I tried this. But i found that there is no difference in insideInset and outsideOverlay.
These two values are diff, either it should have both as Insetor Overlay

我无法正确理解文档。所以参考 ApiDemos Scrollbar 演示,我尝试了这个。但我发现insideInset 和 outsideOverlay没有区别。
这两个值是不同的,它应该同时具有InsetOverlay

updated scrollbar3.xml is

更新的 scrollbar3.xml 是

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<ScrollView
    android:id="@+id/view1"
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:padding="8dip"
    android:scrollbarStyle="insideOverlay"
    android:background="@android:color/white"
    android:overScrollMode="never">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:background="@android:color/darker_gray"
        android:text="@string/scroll_text" />
</ScrollView>

<ScrollView
    android:id="@+id/view2"
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:padding="8dip"
    android:scrollbarStyle="insideInset"
    android:background="@android:color/white"
    android:overScrollMode="never">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:background="@android:color/darker_gray"
        android:text="@string/scroll_text" />
</ScrollView>

<ScrollView
    android:id="@+id/view3"
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:padding="8dip"
    android:scrollbarStyle="outsideOverlay"
    android:background="@android:color/white"
    android:overScrollMode="never">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:background="@android:color/darker_gray"
        android:text="@string/scroll_text" />
</ScrollView>

<ScrollView
    android:id="@+id/view4"
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:padding="8dip"
    android:scrollbarStyle="outsideInset"
    android:background="@android:color/white"
    android:overScrollMode="never">
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:textColor="#ffffff"
        android:background="@android:color/darker_gray"
        android:text="@string/scroll_text" />
</ScrollView></LinearLayout>

I hope someone will see this and clarify...

我希望有人会看到这一点并澄清...

Screenshot for the View Scrollbar styles

视图滚动条样式的屏幕截图

回答by NecipAllef

Above answers didn't quite work for me, so I came up with the following:

以上答案对我来说不太适用,所以我想出了以下内容:

enter image description here

在此处输入图片说明

If this is what you want to achieve, here it goes:

如果这是您想要实现的目标,请执行以下操作:

ListView:

列表显示:

<ListView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbarStyle="outsideOverlay"
    android:scrollbarThumbVertical="@drawable/scrollbar" />

Scrollbar drawable:

滚动条可绘制:

<?xml version="1.0" encoding="utf-8"?>
<layer-list 
     xmlns:android="http://schemas.android.com/apk/res/android">
    <item
        android:drawable="@android:color/transparent"
        android:width="20dp"/>
    <item
        android:drawable="@android:color/holo_red_dark"
        android:right="18dp" />
</layer-list>

Thanks to this answer

感谢这个答案