安卓第三章 布局

这一章主要讲解安卓两大常用布局,RelativeLayout和LinearLayout

RelativeLayout指的是相对布局,控件在该布局中都是相对位置,LinearLayout指的是线性布局,有水平线性和垂直线性。

下面通过一张设计图来解释怎么使用者两个布局。
在这里插入图片描述
两个黑框中的内容使用了横向的LinearLayout
红色框中的内容使用了相对布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity">
        <LinearLayout
            android:id="@+id/first_line"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:weightSum="10"
            android:orientation="horizontal">
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="2"
                android:background="@color/colorPrimaryDark"/>
            <EditText
                android:layout_width="200dp"
                android:layout_height="50dp"
                android:layout_weight="6"
                />
            <ImageView
                android:layout_width="50dp"
                android:layout_height="50dp"
                android:layout_weight="2"
                android:background="@color/colorPrimaryDark"
                />
        </LinearLayout>
    <LinearLayout
        android:id="@+id/second_line"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_below="@+id/first_line"
        android:layout_marginTop="50dp"
        android:weightSum="5">
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="综合"
            android:layout_weight="1"
            android:gravity="center"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="销量"
            android:layout_weight="1"
            android:gravity="center"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="视频"
            android:layout_weight="1"
            android:gravity="center"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="图标"
            android:layout_weight="1"
            android:gravity="center"/>
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="50dp"
            android:text="筛选"
            android:layout_weight="1"
            android:gravity="center"/>
    </LinearLayout>
    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_below="@+id/second_line">
        <ImageView
            android:id="@+id/thumnail"
            android:layout_width="150dp"
            android:layout_height="150dp"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:background="@color/colorAccent"/>
        <TextView
            android:id="@+id/desc"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="手机智能手机 月销过万 vivoZ5X骁龙处理器4G"
            android:layout_toRightOf="@+id/thumnail"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="20dp"
            android:maxLines="2"
            android:ellipsize="end"
            android:textSize="20sp"
            />
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="6.35英寸 | 超长待机 | 上市:2019-5"
            android:layout_below="@+id/desc"
            android:layout_toRightOf="@+id/thumnail"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="15dp"
            android:layout_marginTop="10dp"
            android:textSize="13sp"/>
    </RelativeLayout>
</RelativeLayout>

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值