Android布局控件的继承关系

本文详细介绍了Android中常见的布局控件,包括线性布局、相对布局、帧布局、网格布局的属性和特点。线性布局支持水平和垂直方向,并可设置权重;相对布局能实现复杂的相对位置设置;帧布局采用层层叠加的方式;网格布局则允许指定行列及跨行跨列。同时,文章提及了布局的宽高、内边距、外边距和重力等基础属性的使用。
摘要由CSDN通过智能技术生成

常用属性

宽高
android:layout_width=“30dp”/“match_parent”/“wrap_content”
android:layout_height=“30dp”
盒子模型
padding:内边距
margin:外边距
重力
gravity:center 上下左右(布局设置)
layout_gravity:居中 上下左右(组件设置)

线性布局

常用属性:
方向:orientation (horizontal水平 vertical垂直)
权重:配合宽,高(宽高其中一个用0dp)

相对布局

特点:
有两种相对关系:相对父容器(7个属性 3个居中center 4个对齐align)
相对兄弟容器控件(8个属性 4个位置layout 4个对齐align)

帧布局 FrameLayout

特点:层层叠加覆盖

网格布局 GridLayout

特点:指定行列
常用属性:
行数:android:rowCount=“6”
列数:android:columnCount=“4”
跨列数:layout_columnSpan=“2”
跨行数:layout_rowSpan=“2”
列权重:layout_columnWeight=“1”
行权重:layout_rowWeight=“1”

代码实现

// An highlighted block
<?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="0dp"
        android:orientation="horizontal"
        android:layout_weight="1.2">

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#4688BD"
            android:orientation="horizontal">

            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@mipmap/t11" />

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="P2P活期账本"
                android:textColor="#fff"
                android:textSize="30dp"
                android:layout_marginLeft="50dp"/>


            <ImageView
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:src="@mipmap/t22"
                android:layout_marginLeft="60dp"/>

        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.7"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:scaleType="fitXY"
            android:src="@mipmap/guang" />


    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.2"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/tozi" />


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_marginLeft="140dp"
            android:src="@mipmap/xiangmu" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="0.8">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@mipmap/changping"
            android:scaleType="fitXY"/>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1.2">

       <ImageView
           android:layout_width="wrap_content"
           android:layout_height="wrap_content"
           android:src="@mipmap/tp1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="星火钱包(星火X100)"
            android:textSize="18dp"
            android:layout_marginTop="15dp"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="昨日收益"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="待收总额"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"/>
        </LinearLayout>

    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:orientation="horizontal"
        android:layout_weight="1.2">

        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/tp1"/>

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="星火钱包(星火X100)"
            android:textSize="18dp"
            android:layout_marginTop="15dp"/>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="昨日收益"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="0"/>
        </LinearLayout>
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical">
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="待收总额"/>

            <TextView
                android:layout_width="wrap_content"
                android:layout_height
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值