【线性布局和相对布局的加深理解】:练习和见解(图书显示)

关于线性布局注意内容:
布局中一般RelativeLayout都是在LinearLayout里面,
关于权重weight的加深理解是,weight只有在LinerLayout才能被使用,这是很重要的一点,
RelativeLayout中使用权重weight必须满足条件有:
1.RelativeLayout是在LinearLayout下面进行布局设计
2.LinearLayout必须指定布局方向也就是:android:orientation="vertical"
如果没有指定布局方向的话RelativeLayout使用weight权重也是会出现错误

接下来就是进行设计范围,和基础篇2相同,设计的是图书显示页面:
在这里插入图片描述代码实现如下:


```csharp
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="#8492a6"></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#bfd9d4">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#f4f4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:background="#7ba8b0">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="此处为图书封面"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="3dp"
                android:background="#bfd9d4"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="书名"
                    android:textSize="18sp"/>
            </RelativeLayout>

        </LinearLayout>
        <RelativeLayout
            android:layout_width="3dp"
            android:layout_height="match_parent"
            android:background="#7489ab"></RelativeLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:background="#bfd9d4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="概述"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="作者"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="日期"
                    android:textSize="18sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="#8492a6"></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#bfd9d4">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#f4f4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:background="#7ba8b0">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="此处为图书封面"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="3dp"
                android:background="#bfd9d4"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="书名"
                    android:textSize="18sp"/>
            </RelativeLayout>

        </LinearLayout>
        <RelativeLayout
            android:layout_width="3dp"
            android:layout_height="match_parent"
            android:background="#7489ab"></RelativeLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:background="#bfd9d4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="概述"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="作者"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="日期"
                    android:textSize="18sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="10dp"
        android:background="#8492a6"></LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:background="#bfd9d4">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:background="#f4f4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="2"
                android:background="#7ba8b0">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="此处为图书封面"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="3dp"
                android:background="#bfd9d4"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="书名"
                    android:textSize="18sp"/>
            </RelativeLayout>

        </LinearLayout>
        <RelativeLayout
            android:layout_width="3dp"
            android:layout_height="match_parent"
            android:background="#7489ab"></RelativeLayout>
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="2"
            android:background="#bfd9d4">
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="概述"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="作者"
                    android:textSize="18sp" />
            </RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="5dp"
                android:background="#2e4d5c"></RelativeLayout>
            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:background="#bfd9d4">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="日期"
                    android:textSize="18sp" />
            </RelativeLayout>
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值