如何添加滚动条到Android的一个LinearLayout中?滚动条、Android、LinearLayout

2023-09-04 13:16:07 作者:忽然之间

如何添加滚动条到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.

 
精彩推荐
图片推荐