模仿微信页创建列表布局

这篇实验教程详细介绍了如何使用LinearLayout和TextView、ImageView组件在Android中模仿微信的"发现"页面创建列表布局。通过设置背景色、边距、布局方向以及图标和文字的样式,实现了每个列表项的构建,并通过添加间隔实现列表分组效果。
摘要由CSDN通过智能技术生成

一、实验目标

1、模仿微信“发现”页创建列表布局;

2、学习使用Textview,imageview,LinearLayout。

二、实验步骤

1.逻辑梳理

​ 页面上包含五组列表,每组包含1-2个列表项,设计方式如下:首先首先设计一个外部总垂直布局,包含所有的列表组,然后写五个LinearLayout来构建这五个列表组,最后进行列表组之间的间隔样式搭建。

2.代码实现

(1)创建父布局,然后对对父布局设置背景色和垂直方向。

(2)构建第一个列表组,设置设置宽高,背景色以及垂直方向。

(3)创建列表组里的第一个图标,设置宽高、背景色、距离左边的距离等。

(4)创建列表组中的汉字,设置汉字宽高、字体颜色、字体样式、字体大小、与左侧的距离等。
(5)创建列表组右边的箭头,设置宽和高,背景,与右边的距离等。

(5)根据第一个列表组创建其他的列表组。

(6)设计间隔样式,在需要间隔的列表中添加android:layout_marginTop属性。

三、程序代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:background="#C0C0C0"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/icon_pengyou"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="朋友圈"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="vertical">
    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/saoyisao"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>

        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="扫一扫"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>

    <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/yaoyiyao"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="摇一摇"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>

    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="vertical">

        <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/kanyikan"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="看一看"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>

        <LinearLayout
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/souyisou"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="搜一搜"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>
    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="15dp"
        android:layout_width="match_parent"
        android:layout_height="120dp"
        android:orientation="vertical">
        <LinearLayout
            android:background="#fff"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="60dp">

            <ImageView
                android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:background="@mipmap/gouwu"
                android:layout_width="40dp"
                android:layout_height="40dp">

            </ImageView>
            <TextView
                android:layout_marginLeft="10dp"
                android:textStyle="bold"
                android:textColor="#333"
                android:textSize="18dp"
                android:gravity="center_vertical"
                android:layout_weight="1"
                android:text="购物"
                android:layout_width="0dp"
                android:layout_height="match_parent">

            </TextView>
            <ImageView
                android:layout_marginRight="15dp"
                android:layout_gravity="center_vertical"
                android:background="@mipmap/right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            </ImageView>

        </LinearLayout>

        <LinearLayout
            android:background="#fff"
            android:orientation="horizontal"
            android:layout_width="match_parent"
            android:layout_height="60dp">

            <ImageView
                android:layout_margin="15dp"
                android:layout_gravity="center_vertical"
                android:background="@mipmap/youxi"
                android:layout_width="40dp"
                android:layout_height="40dp">

            </ImageView>
            <TextView
                android:layout_marginLeft="10dp"
                android:textStyle="bold"
                android:textColor="#333"
                android:textSize="18dp"
                android:gravity="center_vertical"
                android:layout_weight="1"
                android:text="游戏"
                android:layout_width="0dp"
                android:layout_height="match_parent">

            </TextView>
            <ImageView
                android:layout_marginRight="15dp"
                android:layout_gravity="center_vertical"
                android:background="@mipmap/right"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

            </ImageView>

        </LinearLayout>

    </LinearLayout>
    <LinearLayout
        android:layout_marginTop="15dp"
        android:background="#fff"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="60dp">

        <ImageView
            android:layout_margin="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/xioachengxu"
            android:layout_width="40dp"
            android:layout_height="40dp">

        </ImageView>
        <TextView
            android:layout_marginLeft="10dp"
            android:textStyle="bold"
            android:textColor="#333"
            android:textSize="18dp"
            android:gravity="center_vertical"
            android:layout_weight="1"
            android:text="小程序"
            android:layout_width="0dp"
            android:layout_height="match_parent">

        </TextView>
        <ImageView
            android:layout_marginRight="15dp"
            android:layout_gravity="center_vertical"
            android:background="@mipmap/right"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">

        </ImageView>

    </LinearLayout>

</LinearLayout>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

沈辞-

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值