Android ListView实现类似朋友圈的复杂布局

这篇博客探讨了如何在Android中使用ListView优化类似朋友圈的复杂布局。通过拆分单个信息的布局为多个item,如title, body, image和bottom,提高列表滚动的流畅性。文章提供了一个实例,将News类拆分为多个ListView items,并展示了具体实现步骤。" 104514064,9344907,MATLAB bar图表错误:'set'输入参数无效,['MATLAB'],"['MATLAB', 'bar图表', 'set函数', '错误修复']

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

开发中时常会遇到用ListView实现类似朋友圈列表的复杂布局,如果一个条信息即为ListView中一项时,那么单个布局的结构会变的很复杂,也会影响列表滚动的流畅性。由于Adapter可以使用多种布局,所以这里采用的方式是将单个信息的布局拆分为多个ListView的item来达到优化的目的。借用facebook新闻页ListView优化中的一张图



先上一张效果图:


这里将一条信息的页面拆分为4个:title, body, image, bottom。

item_title.xml

<?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"
              android:background="@android:color/white"
              android:padding="5dp">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="New Text"
        android:id="@+id/title"/>
</LinearLayout>

item_body.xml

<?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"
              android:padding="5dp"
              android:background="@android:color/white">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Large Text"
        android:lines="4"
        android:id="@+id/body"/>
</LinearLayout>
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值