1 ListView item 布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context=".item">
<TextView
android:id="@+id/DocName"
android:layout_marginLeft="10dp"
android:layout_width="0dp"
android:layout_weight="1"
android:text="helloworld"
android:layout_height="wrap_content"/>
<ImageView
android:id="@+id/DocName_tv"
android:layout_width="50dp"
android:layout_height="wrap_content"
android:src="@mipmap/go_launcher"/>
</LinearLayout>
2 主显示页布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".PolicListActivity">
<!--头部-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="@color/colorRed"
android:gravity="center">
<ImageView
android:id="@+id/iv_back"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:src="@drawable/ic_left_back"
android:onClick="onClick">
</ImageView>
<TextView
android:id="@+id/tv_tittle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginRight="20dp"
android:text="政策加法器"
android:textSize="16dp"/>
</LinearLayout>
<!--列表和按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="700dp"
android:orientation="vertical">
<!-- 中间列表-->
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ListView
android:id="@+id/ListView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
</ListView>
</LinearLayout>
</ScrollView>
<!-- 底部按钮-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:id="@+id/bt_goBack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:text="返回主页"
android:layout_margin="@dimen/marginSize"
android:background="@color/colorRed"
android:textSize="18dp"
android:onClick="onClick"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
3 文件+图片保存为List对象
//添加 > 图片
ArrayList<Map<String, Object>> dataList = new ArrayList<Map<String, Object>>();
for (int i =0;i<10;i++){
Log.d("oldDocName", String.valueOf(oldDocName.get(i)));
Map<String,Object> map = new HashMap<String,Object>();
String string = (String) oldDocName.get(i).getOldDocName();
//去掉后缀名
String filename = string.substring(0,string.lastIndexOf("."));
map.put("text",filename);
map.put("pic",R.mipmap.go_launcher);
dataList.add(map);
}
//适配器
SimpleAdapter adapter = new SimpleAdapter(this, dataList,
R.layout.item, new String[] { "text", "pic" },
new int[] { R.id.DocName, R.id.DocName_tv });
//ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,android.R.layout.simple_expandable_list_item_1, oldDocName);
//实现列表的显示
listView.setAdapter(adapter);
4 效果图