文章目录
一、 前言
- 了解帧式布局用途
- 熟悉帧式布局常用属性
- 掌握线性布局嵌套帧式布局
- 有时候我们在设计安卓用户面时,有种需求,一个控件会层叠在另一个控件上,此时用线性布局就无法实现,就得使用一个新的布局——帧式布局。
二、笔记3.2

(一)帧式布局概述
1、布局特点
- 帧式布局是一种层叠式的布局,后添加的控件会层叠在先添加的控件上。
2、继承关系图
- FrameLayout类是ViewGroup的子类

3、常用属性
| 属性 | 含义 |
|---|---|
| scrollbars | 滚动条(none、horizontal、vertical) |
| layout_marginTop | 上边距 |
| layout_marginBottom | 下边距 |
| layout_marginLeft | 左边距 |
| layout_marginRight | 右边距 |
| paddingLeft | 左内边距 |
| paddingRight | 右内边距 |
| paddingTop | 上内边距 |
| paddingBottom | 下内边距 |
| background | 背景(背景色、背景图、背景选择器) |
(二)案例演示:切换颜色
1、创建安卓应用
-
基于
Empty Activity创建安卓应用 -SwitchColor


-
单击【Finish】按钮

2、主布局资源文件
- 主布局资源文件 -
activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical"
tools:context=".MainActivity">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp">
<TextView
android:id="@+id/tv_bottom"
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_gravity="center"
android:background="#ff0000"
android:text="@string/bottom"
android:textColor="#ffff00"
android:textSize="30sp" />
<TextView
android:id="@+id/tv_middle"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center"
android:background="#00ff00"
android:text="@string/middle"
android:textColor="#ffff00"
android:

本文介绍了Android Studio中的帧式布局,详细讲解了其特点、继承关系及常用属性。通过一个切换颜色的案例,展示了如何创建安卓应用、设置主布局资源文件、实现功能,并探讨了优化切换颜色的算法,适合初学者了解和掌握帧式布局的应用。
1049

被折叠的 条评论
为什么被折叠?



