第2章布局管理器05-帧(框架)布局管理器.ppt
文本预览下载声明
第2章 布局管理器 帧(框架)布局管理器 本章目标 掌握帧布局管理器的使用特点; 可以在布局管理器之中使用帧布局进行排列; 掌握滚动视图ScrollView和水平滚动视图HorizontalScrollView。 FrameLayout布局 FrameLayout布局(帧布局)就是在屏幕上开辟一个区域填充所有的控件,使用FrameLayout布局会将所有的控件都放在屏幕的左上角,而且所有的组件可以层叠进行显示,这些帧都会根据gravity属性执行自动对齐。 采用帧布局设计界面后,只能在屏幕左上角显示单个控件。如果添加多个控件,则会按顺序叠加在屏幕的左上角重叠显示,但会透明显示出之前控件的文本内容。 FrameLayout xmlns:android=/apk/res/android !--帧布局ID -- android:id= !-- 布局的高度和宽-- android:layout_width= android:layout_height= !--任意控件-- widgets …… / …… …… /FrameLayout FrameLayout布局 使用FrameLayout进行布局 ?xml version=1.0 encoding=utf-8? FrameLayout ?使用框架布局 xmlns:android=/apk/res/android android:id=@+id/FrameLayout01 ?此布局的ID,程序中使用 android:layout_width=wrap_content ?此布局管理器将填充整个屏幕宽度 android:layout_height=wrap_content?此布局管理器将填充整个屏幕高度 EditText ?文本输入框 android:id=@+id/myinput“ ?此组件ID,程序中使用 android:text=请输入您的姓名...“ ?默认显示文字 android:layout_width=wrap_content? 组件宽度为文字宽度 android:layout_height=wrap_content/?组件宽度为文字高度 Button ?普通按钮 android:id=@+id/mybut“ ?此组件ID,程序中使用 android:text=按我 ?默认显示文字 android:layout_width=wrap_content? 组件宽度为文字宽度 android:layout_height=wrap_content/?组件高度为文字高度 /FrameLayout 使用FrameLayout进行布局 FrameLayout android.widget.FrameLayout类继承结构: java.lang.Object ? android.view.View ? android.view.ViewGroup ? android.widget.FrameLayout 滚动视图ScrollView和水平滚动视图HorizontalScrollView 滚动视图用于为其它组件添加滚动条,在默认的情况下,当窗体中内容比较多,而一屏显示不下时, 超出的部分不能被用户所看到.因为Android的布局管理器本身没有提供滚动屏幕的功能.如果 要让其滚动,就要使用滚动视图ScrollView 滚动视图ScrollView 滚动视图ScrollView ScrollView支持视图垂直滚动,只能拥有一个直接子类。通常用的子元素是垂直方向的LinearLayout,展示一系列的垂直内容。在使用ScrollView时,需要将其他布局嵌套在ScrollView之内。 ScrollView xmlns:android=/apk/res/android !--滚动视图ID -- android:id=@+id/scollView1? android:layout_width=match_parent android:layout_height=match_parent ?LinearLayout xmlns:android=/apk/res/android xmlns:tools=/tools android:id=@+id/LinearLayout1 android:layout_width=match_parent android:layout_height=wrap_content !-
显示全部