安卓常见布局

本文介绍了安卓开发中常见的布局类型,包括线性布局、相对布局的使用方法,并通过实例详细解析了相对布局的属性设置,如如何设置按钮的位置(上边、下边、左边、右边、左上、右上、左下、右下)以实现灵活的界面布局。
摘要由CSDN通过智能技术生成

一线性布局

线性布局中嵌套的组件之间不可以重叠, 有一个布局方向 ,水平或者竖直,依次排开.在竖直布局下,左对齐、右对齐,水平居中生效.在水平布局下,顶部对齐、底部对齐、竖直居中生效. 线性布局中有个很重要的概念----权重:按比例分配屏幕的剩余宽度或者高度 谷歌推荐使用时将空间宽度或高度设置为0dp.在定义布局颜色时候,我们可以使用谷歌给我们预定义好的颜色代码"@android:color/dark" 
简单示例:
<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_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        >
        <TextView 
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ff0000"
            />
        <TextView 
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#ffffff"
            />
        <TextView 
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="#000000"
            />
        <TextView 
            android:layout_weight="1"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@android:color/darker_gray"
            />
    </LinearLayout>

    <LinearLayout 
        android:layout_weight="1"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="vertical"
        >
        <TextView 
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="#00ff00"
            />
        <TextView 
            android:layout_weight="1"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:background="@android:color/darker_gray"
            />
        <TextView 
            android:layout_weight="1"
            android:layout_width="match_parent"
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值