Android Studio 笔记3.2 帧式布局

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

一、 前言

  1. 了解帧式布局用途
  2. 熟悉帧式布局常用属性
  3. 掌握线性布局嵌套帧式布局
  • 有时候我们在设计安卓用户面时,有种需求,一个控件会层叠在另一个控件上,此时用线性布局就无法实现,就得使用一个新的布局——帧式布局。

二、笔记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&
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值