Android实战之Scrollbar Activity
Android实战之Scrollbar Activity
Android中几个常用的Layout虽然有scrollbar属性,但是并不能实现当其中内容太多时自动在Activity上出现Scrollbar,后来发现对于这种情况其实是需要使用ScrollView来处理的,具体配置可以如下:
- <?xml version="1.0" encoding="utf-8"?>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <ScrollView
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <LinearLayout
- android:id="@+id_scrollbar/layout1"
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- ...
- </LinearLayout>
- </ScrollView>
- </LinearLayout>
或者
- <?xml version="1.0" encoding="utf-8"?>
- <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- <LinearLayout
- android:orientation="vertical"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content" >
- ...
- </LinearLayout>
- </ScrollView>
其中需要注意的是ScrollView内部只能有一个子元素,所以需要把所有的子元素放到一个LinearLayout内部。
评论暂时关闭