Android 各种布局技术-五大布局对象

本文深入解析了Android中的FrameLayout、LinearLayout、AbsoluteLayout、RelativeLayout和TableLayout等布局方式,通过示例展示了如何使用这些布局实现不同功能。

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

android:layout_width只能设置fill_parent(横向填充整个屏幕)或wrap_content(横向填充控件本身大小)
android:width设置具体控件的横向大小 单位是像素

 

FrameLayout,  LinearLayout ,  AbsoluteLayout,  RelativeLayout, TableLayout.

 

----- FrameLayout-----

 

Demo1:

activity_main.xml

ok

<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" >

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="100dp"
        android:inputType="textPassword" />

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/hello_world"
        tools:context=".MainActivity" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/hello"
        android:textColor="#0000ff"
        android:textColorHighlight="#aaaaaa"
        android:textSize="20dp"
        android:textStyle="bold"
        tools:context=".MainActivity" />

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="@string/world"
        android:textColor="#333333"
        android:textStyle="italic"
        tools:context=".MainActivity" />

</FrameLayout>

 

res/values/目录下的xml文件中设置@string对应的value

----------

??

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
	<ImageView  
	    android:layout_width="fill_parent" 
	    android:layout_height="fill_parent" 
	    android:src="@drawable/movie"
	    />
	<ImageView  
	    android:layout_width="wrap_content" 
	    android:layout_height="wrap_content" 
	    android:src="@drawable/play"
	    android:layout_gravity="center"
	    />
</FrameLayout>

movie 和 play 是res/drawable目录下对应的图片文件名

  

 

----- LinearLayout(线性布局)-----

 

 

----

-----AbsoluteLayout(绝对布局)----

----

----

----

---- RelativeLayout(相对布局)  -----

----

----

----

----- TableLayout(表格布局) -----

 

----

----

----

----

----

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值