Android:如何自动显示垂直滚动条?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1497755/
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
Android: How to automatically display vertical scrollbar?
提问by Niko Gamulin
I created a user form which fits the window in vertical orientation. When the user slides the keyboard the form doesn't fit the screen (horizontal orientation). I tried to add the scrollbar but it is not visible.
我创建了一个适合垂直方向的窗口的用户表单。当用户滑动键盘时,表单不适合屏幕(水平方向)。我试图添加滚动条,但它不可见。
I would appreciate if anyone could show how to modify the following layout file in order to display scrollbar when the orientation is set to horizontal.
如果有人可以展示如何修改以下布局文件以在方向设置为水平时显示滚动条,我将不胜感激。
Thanks!
谢谢!
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true">
...
</LinearLayout>
回答by CommonsWare
Remove the scrollbar attributes and wrap the whole thing in a ScrollView
.
删除滚动条属性并将整个内容包装在ScrollView
.
回答by Alex Vishnev
You can't replace the LinearLayout with ScrollView because ScrollView only supports one Direct Child and LinearLayout may have many. So the only option i see is to wrap
你不能用 ScrollView 替换 LinearLayout 因为 ScrollView 只支持一个 Direct Child 而 LinearLayout 可能有很多。所以我看到的唯一选择是包装
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:overScrollMode="always"
android:isScrollContainer="true"
android:scrollbarAlwaysDrawVerticalTrack="true"
android:scrollbarStyle="outsideInset"
android:scrollbars="vertical">
You can pick a variety of other attributes. These worked for my implementation. It is the first container in my layout.LinearLayout is a child of this container. Other UI elements are part of LinearLayout
您可以选择各种其他属性。这些对我的实现有用。它是我布局中的第一个容器。LinearLayout 是此容器的子项。其他 UI 元素是 LinearLayout 的一部分
Hope this helps... Alex
希望这有助于...亚历克斯