Java安卓 使用视图组 布局

1. 线性布局 LinerLauout

线性布局可以是单行列视图。行可以是水平或垂直的;
可以使用android:orientation

属性参数
android:orientationhorizonal和vertical
android:widthwrap_content和match_parent
adnroid:widthwrap_content和match_parent

linelayout.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FFFAF0"
        android:gravity="center"
        android:text="TextView(显示框)"
        android:textColor="#EA5246"
        android:textSize="18sp"
        android:textStyle="bold|italic" />
    
     <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#FF4500"
        android:gravity="center"
        android:text="TextView(显示框)"
        android:textColor="#EA5246"
        android:textSize="18sp"
        android:textStyle="bold|italic" />
     
      <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#808080"
        android:gravity="center"
        android:text="TextView(显示框)"
        android:textColor="#EA5246"
        android:textSize="18sp"
        android:textStyle="bold|italic" />
      
       <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:gravity="center"
        android:text="TextView(显示框)"
        android:textColor="#EA5246"
        android:textSize="18sp"
        android:textStyle="bold|italic" />

</LinearLayout>

在这里插入图片描述

2. 表格布局 TableLayout

TableRow决定行数,里面的决定列数

tablelayout.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <TableRow>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试11" />
        
    </TableRow>

    <TableRow>

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试21" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试22" />
    </TableRow>
    
    <TableRow>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试31" />
        
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试32" />
        
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="测试33" />
        
    </TableRow>

</TableLayout>

在这里插入图片描述

3. 框架布局 FrameLayout

次布局用于蕾西堆栈格式从下往上添加视图,也就是一层一层往上覆盖。
framelayout.xml

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center" >

    <TextView
        android:layout_width="150sp"
        android:layout_height="150sp"
        android:background="#000000" 
        android:gravity="center"
        />
    
    <TextView
        android:layout_width="100sp"
        android:layout_height="100sp"
        android:background="#FFA07A" 
        android:gravity="center"
        />
    
    <TextView
        android:layout_width="50sp"
        android:layout_height="50sp"
        android:background="#FFD700" 
        android:gravity="center"
        />

</FrameLayout>

在这里插入图片描述

4. 相对布局 RelativeLayout

<RelativeLayout 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"
    tools:context="${relativePackage}.${activityClass}" >

    <Button
        android:id="@+id/btn1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

</RelativeLayout>

5. 绝对布局 RelativeLayout

绝对布局不推荐,就可以不看啦

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <CheckBox
        android:id="@+id/checkBox1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="42dp"
        android:layout_y="92dp"
        android:text="CheckBox" /> 

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_x="22dp"
        android:layout_y="14dp"
        android:text="Button" />

</AbsoluteLayout>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

有勇气的牛排

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值