java.lang.Object | ||||
↳ | android.view.View | |||
↳ | android.view.ViewGroup | |||
↳ | android.widget.FrameLayout | |||
↳ | android.widget.HorizontalScrollView |
类概述
用于布局的容器,可以放置让用户使用滚动条查看的视图层次结构,允许视图结构比手机的屏幕大. HorizontalScrollView 是一种 框架布局
, 这意味着你可以将包含要滚动的完整内容的子视图放入该容器; 该子视图本身也可以是具有复杂层次结构的布局管理器.一般使用横向的 LinearLayout
作为子视图,使用户可以滚动其中显示的条目.
文本视图
类也有其自身的滚动处理,不需要嵌入滚动视图; 但二者可以组合使用,其效果与将文本视图放入很大容器中一样.
HorizontalScrollView 只支持水平方向的滚动。 For vertical scrolling, use either ScrollView
or ListView
.
实例:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<HorizontalScrollView
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:scrollbarAlwaysDrawHorizontalTrack="false">
<LinearLayout
android:id="@+id/LinearLayout02"
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="fill_parent">
<Button
android:text="1"
android:id="@+id/Button01"
android:layout_width="200px"
android:layout_height="wrap_content" />
<Button android:text="2"
android:id="@+id/Button02"
android:layout_height="wrap_content"
android:layout_width="200px" />
<Button android:text="3"
android:id="@+id/Button03"
android:layout_width="200px"
android:layout_height="wrap_content" />
<Button android:text="4"
android:id="@+id/Button04"
android:layout_width="200px"
android:layout_height="wrap_content" />
<Button android:text="5"
android:id="@+id/Button05"
android:layout_width="200px"
android:layout_height="wrap_content" />
<Button android:text="6"
android:id="@+id/Button06"
android:layout_height="wrap_content"
android:layout_width="200px" />
<Button
android:text="7"
android:id="@+id/Button07"
android:layout_width="200px"
android:layout_height="wrap_content" />
<Button android:text="8"
android:id="@+id/Button08"
android:layout_width="200px"
android:layout_height="wrap_content" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
package com.example.activity01;
import android.app.Activity;
import android.os.Bundle;
public class ScrollerActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}