本文主要是介绍Android布局(3)--帧布局(FrameLayout),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
在帧布局中,每添加一个组件都将创建一个空白区域,通称之为一帧。这些帧都要被对齐到屏幕左上角,不能单独为子组件指定位置。第一个添加到帧布局中的子组件显示在最底层,最后一个添加的子组件位于最顶层,上一层的子组件会覆盖下一层的子组件,这种显示方法类似于堆栈。因此又称为堆栈布局。帧布局的大小由子组件中尺寸最大的子组件来决定。
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 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:paddingBottom="@dimen/activity_vertical_margin"android:paddingLeft="@dimen/activity_horizontal_margin"android:paddingRight="@dimen/activity_horizontal_margin"android:paddingTop="@dimen/activity_vertical_margin"tools:context="com.example.demo.FrameLayout"><TextViewandroid:layout_width="300dp"android:layout_height="300dp"android:id="@+id/textView1"android:background="#FFD700"android:text="第一行"android:gravity="bottom"android:textSize="12pt"/><TextViewandroid:layout_width="260dp"android:layout_height="260dp"android:id="@+id/textView2"android:background="#FFA07A"android:text="第二行"android:gravity="bottom"android:textSize="14pt"/><TextViewandroid:layout_width="220dp"android:layout_height="220dp"android:id="@+id/textView3"android:text="第三行"android:background="#FF00FF"android:textSize="16pt"/><TextViewandroid:layout_width="180dp"android:layout_height="180dp"android:id="@+id/textView4"android:background="#FF0000"android:text="第四行"android:gravity="bottom"android:textSize="16pt"/>
</FrameLayout>
这篇关于Android布局(3)--帧布局(FrameLayout)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!