Android FrameLayout

本文介绍了Android开发中常用的五大布局:帧布局(FrameLayout)、线性布局(LinearLayout)、绝对布局(AbsoluteLayout)、相对布局(RelativeLayout)及表格布局(TableLayout)。详细解释了帧布局的工作原理和使用方法,并提供了实例代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Android  Layout有 五大布局对象 , 分别是 FrameLayout( 布局 ),LinearLayout ( 线性布局 ),AbsoluteLayout( 绝对布局 ),RelativeLayout( 相对布局 ),TableLayout( 表格布局 ).  

FrameLayout: 该布局container 可以用来占有屏幕的某块区域来显示单一的对象,可以包含有多个widgets 或者是container ,但是所有被包含的widgets 或者是container 必须被固定到屏幕的左上角,并且一层覆盖一层,不能通过为一个widgets 或者是container 指定一个位置。Container 所包含的widgets 或者是container 的队列是采用的堆栈的结构,最后加进来的widgets 或者是container 显示在最上面。所以后一个widgets 或者是container 将会直接覆盖在前一个widgets 或者是container 之上,把它们部份或全部挡住(除非后一个widgets 或者是container 是透明的,必须得到FrameLayout Container 的允许)。

其中Main.xml   代码如下:

<? xml  version = "1.0"  encoding = "utf-8" ?>

< FrameLayout  xmlns:android = "http://schemas.android.com/apk/res/android"

     android:orientation = "vertical"

     android:layout_width = "fill_parent"

     android:layout_height = "fill_parent"

     >

< TextView  

          android:layout_width = "fill_parent"

          android:layout_height = "wrap_content"

          android:text = "@string/hello"

     />

      < TextView

          android:textColor  =  "#0000FF"

          android:layout_width  =  "wrap_content"

          android:layout_height  =  "wrap_content"

          android:text  =  "@string/hello2"

          />

</ FrameLayout >

Strings.xml 代码如下:

<? xml  version = "1.0"  encoding = "utf-8" ?>

< resources >

     < string  name = "hello" > Hello World, LayoutTestActivity! </ string >

     < string  name = "app_name" > LayoutTest </ string >

     < string  name = "hello2" > Hello World, I can not be LOST! </ string >

</ resources>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值