之前学习的ListView都是采用android系统自带的子项目布局,比如android.R.layout.simple_list_item_1(单行文字),以及android.R.layout.simple_list_item_2(双行文字)
但是实际软件开发中我们更希望ListView的子项目的布局更加丰富,不仅有文字还有图片,图标之类的。当然位置也可以自定义了。下面我就来接受下怎么制作一个自定义的ListView的Item布局并通过BaseAdpater绑定 显示。
当然首先你需要设计一个输入自己ListView选项Item的布局:比如我设计的就是下面这样
每个ListView选项包括一个头像ImageView, 姓名TextView,动态Dynamic,以及一个查看Button。点击查看Button的时候会在最顶部的两个TextView中显示点击选项的姓名和动态文字。效果如下面所示:
下面是选项布局文件holderlistviw.xml中的代码:
<span style="font-size:14px;"><?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="120dp"
android:orientation="horizontal" >
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="match_parent" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="5dp"
android:orientation="vertical" >
<TextView
android:id="@+id/name"