一步一步学android之控件篇——ListView自定义显示数据格式

本篇博客深入探讨如何在ListView中使用SimpleAdapter自定义显示数据格式,以实现图文混排的效果。通过实例,展示如何创建包含图片和文字的ListView项模板,达到显示女明星照片、姓名和简介的需求,并介绍点击图片查看原图的功能。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

上一篇博客说了ListView的基本使用,这篇将是对ListView的使用进行一个提高,在日常生活中,如果单单给你看一些图片,你可能都不知道这个图片表达的什么意思,但是要是在图片旁边写的备注或者加个名字,我们就会很清楚的知道这张图片是什么,所以就要使用到SimpleAdapter类了,下面用个例子来说明SImpleAdapter在ListView中的作用。

下面要实现的需求是,用ListView显示9个女明星的照片,姓名和简介,然后点击照片可以查看原图。

效果如下:



从上面的效果图可以看出来这个ListView的项是包含了图片和文字两个对象的,所以我们需要先定义一个布局文件来作为显示每一项的模板,listview_item.xml:

<?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="horizontal" >

    <ImageView
        android:id="@+id/people"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_margin="10dp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="TextView" />

        <TextView
            android:id="@+id/introduce"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="10dp"
            android:text="TextView" />

    </LinearLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:orientati
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值