Android布局控件(包含线性布局,框架布局,表格布局,相对布局,约束布局)

Android提供了许多布局空间,对于不同的格式需求选择不同的布局控件,可以大大简化代码操作。下面为大家介绍一下以下经常用到的五种布局。

对了,补充一下,往常Android只有约束布局可以直接在Design页面拖动,现在都可以了。不过不推荐。

1.linear_layout(线性布局)

线性布局正如其名,他是呈线性分布的布局。只能控制水平或者垂直方向排布控件。可以用于设置登陆界面等简单排布的界面,下面有颜色填充一个线性布局,大家可以参考一下:

重点在于这句:android:orientation=“vertical”  在这个布局中控件垂直分布

                         android:orientation=“horizontal”  在这个布局中控件水平分布

如果复杂一些,大家灵活运用,各种嵌套肯定没问题。

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

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:orientation="vertical"
        android:paddingLeft="10dp">              //设置左内边距

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="第一行"
            android:textColor="#ffffff"
            android:background="#550000"
            android:layout_weight="1"
            android:gravity="center_vertical"     //设置控件位置
            android:paddingLeft="20dp" />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="第二行"
            android:textColor="#ffffff"
            android:background="#005500"
            android:layout_weight="1"
            android:gravity="center_horizontal|center_vertical"/>
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="第三行"
            android:textColor="#ffffff"
            android:background="#000055"
            android:layout_weight="1"
            android:gravity="right|center_vertical"
            android:layout_marginRight="10dp"/>     //设置右外边距

    </LinearLayout>

    <LinearLayout
        android:layout_width="
  • 4
    点赞
  • 18
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值