第二篇Android零基础自学笔记——线性布局(LinearLayout)

这篇博客介绍了Android线性布局(LinearLayout)的基础知识和特点,包括垂直或水平排列组件,并通过实战例子展示了如何使用线性布局仿制微信我的界面,提供了界面解析图和完整代码。
摘要由CSDN通过智能技术生成

Android的前生今世,感兴趣的小伙伴点击百度一下吧
百度回来的各位,接下来我们进入项目实战学习
首先我们就先从看得到的入手,探究UI开发吧——实战两个常用基本布局
           1. 线性布局(LinearLayout)——本篇讲解
           2. 相对布局(RelativeLayout)——下篇
简单说说线性布局的特点:
           1.线性布局是将放入其中的组件按照垂直或水平方向来布局
           2.控制放入其中的组件横向排列或纵向排列
           3.在线性布局中,每一行(针对垂直排列)或每一列(针对水平排列)中只能放一个组件
           4.Android的线性布局不会换行,当组件一个挨着一个排列到窗体的边缘后,剩下的组件将不会被显示出来


使用线性布局(LinearLayout)来仿一个微信我的界面吧


——界面布局解析图及效果图——



相信这个界面还原度可以高达99.999999999999999%

贴上界面的完整代码

仅用一种布局完成,导致代码比较复杂,请结合上面的界面解析图看哦


<?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"
    android:background="#F1EEEE"
>
    <!--装载相机按钮的线性布局-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#fff"
        android:orientation="vertical"
        >
        <!--相机按钮-->
        <ImageView
            android:layout_width="24dp"
            android:layout_height="24dp"
            android:src="@drawable/photo"
            android:layout_gravity="right"
            android:layout_marginTop="12dp"
            android:layout_marginRight="12dp"
            />
    </LinearLayout>
<!--个人信息栏线性布局水平-->
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="horizontal"
        android:gravity="center_vertical"
        android:background="#fff"
        >
        <!--头像-->
        <ImageView
            android:layout_width="80dp"
            android:layout_height="80dp"
            android:src="@drawable/abc"
            android:layout_marginLeft="15dp"
            />
        <!--线性布局垂直-->
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_marginLeft="10dp"
            >
            <!--网名-->
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Lionel Wang"
                android:textColor="#000"
                android:textSize="24sp"
                />
            <!--线性布局水平-->
            <LinearLayout
                android:
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值