如何添加滚动条到Android的一个LinearLayout中? [英] How do I add scrollbars to a LinearLayout in Android?

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

问题描述

如何添加滚动条到Android的一个看法?

How do I add scrollbars to a view in Android?

我试图通过添加机器人:在我的布局XML文件,但它的垂直的LinearLayout :滚动条不管用。

I tried by adding android:scrollbars:"vertical" to the LinearLayout in my layout XML file but it is not working.

我还以为是滚动条默认情况下,Android的绘制,但它似乎这种方式确实。看来我们要绘制它自己 - 如何做到这一点

I thought scrollbars were drawn by default in Android but it does not seem that way. It seems we have to draw it ourselves - how do I do this?

推荐答案

您不能添加滚动条到的LinearLayout ,因为它不是一个滚动的容器。

You cannot add scrollbars to a LinearLayout because it is not a scrollable container.

只有滚动的容器,如滚动型 Horizo​​ntalScrollView 的ListView 的GridView ExpandableListView 显示滚动条。

Only scrollable containers such as ScrollView, HorizontalScrollView, ListView, GridView, ExpandableListView show scrollbars.

我建议你把你的的LinearLayout 滚动型这将默认显示垂直滚动条,如果有足够的内容滚动。

I suggest you place your LinearLayout inside a ScrollView which will by default show vertical scrollbars if there is enough content to scroll.

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        >

        <!-- Your content goes here -->   

    </LinearLayout>
</ScrollView>

如果您希望始终显示垂直滚动条,再加入安卓scrollbarAlwaysDrawVerticalTrack =真正的滚动型。需要注意的高度的LinearLayout 设置为 WRAP_CONTENT - 这意味着高度的的LinearLayout 可以比大的滚动型如果有足够的内容 - 在这种情况下,你将能够滚动你的的LinearLayout 上下。

If you want the vertical scrollbar to always be shown, then add android:scrollbarAlwaysDrawVerticalTrack="true" to your ScrollView. Note the height of the LinearLayout is set to wrap_content - this means the height of the LinearLayout can be larger than that of the ScrollView if there is enough content - in that case you will be able to scroll your LinearLayout up and down.

这篇关于如何添加滚动条到Android的一个LinearLayout中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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