7.1. ScrollView (滚动视图)
7.1.1. ScrollView (滚动视图,只支持垂直方向的滚动)
滚动视图的原理:
滚动视图的使用形式与各个布局管理器的操作形式类似,唯一不同的是,所有的布局管理器之中,
可以包含多个组件,而滚动视图里只能有一个组件,所以所谓的滚动视图指的就是提供一个专门
的容器,这个容器里面可以装下多于屏幕宽度的组件,而后采用拖拽的方式显示所有在ScrollView
中的组件。
ScrollView只支持垂直方向的滚动
<?xml version="1.0" encoding="utf-8"?> <ScrollView android:id="@+id/myscroll" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent"> <LinearLayout android:orientation="vertical" android:id="@+id/mylinear" android:layout_width="fill_parent" android:layout_height="fill_parent"> </LinearLayout> </ScrollView> |
不是说滚动视图可以保存多个组件吗?那么为什么又要建立一个内嵌的线性布局管理器呢?
因为在滚动视图中只能有一个组件,要想添加其他的组件,就得使用内嵌的布局管理器,然后在程序里面向
此组件中添加其他组件,所以此组件使用内嵌的线性布局管理器完成。
为了可以让内嵌的布局管理器加入多个显示的组件,而且又保证程序不这么的冗余,所以现在可以通过Activity
程序进行控制,向内嵌布局管理器中增加多个组件。
package com.makyan.demo; import android.app.Activity; import android.os.Bundle; import android.view.ViewGroup; import android.widget.Button; import android.widget.LinearLayout; public class ScrollViewActivity extends Activity { private String data[] = { "杨雄工作科技", "www.makyan.cn", "讲师:杨雄进", "中国高校讲师联盟", "www.makyan.com", "咨询邮箱:makyan_sophia@sina.com" |