首先来配置xml文件,main.xml和item.xml。
main.xml:主界面布局,包含一个ListView组件。
<?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" >
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent">
</ListView>
</LinearLayout>
</pre><h1>item.xml:自定义ListView子项的布局文件,包含一个Imageview和两个TextView。</h1><pre class="html" name="code"><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal"
>
<ImageView
android:id="@+id/item_img"
android:layout_width="80dp"
android:layout_height="40dp"
android:scaleType="fitXY"
android:layout_margin="10dp"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"