Android课程---优化ListView列表视图
2016-04-09 16:59
369 查看
activity_ui4.xml
layout_simple.xml
UIActivity4.java
效果图:
<?xml version="1.0" encoding="utf-8"?> <ListView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:id="@+id/sa_1"> </ListView>
layout_simple.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="wrap_content"> <ImageView android:layout_width="70dp" android:layout_height="70dp" android:src="@drawable/yuantu" android:id="@+id/lv2"/> <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:layout_gravity="center_vertical" android:layout_marginLeft="20dp"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="美食图片" android:id="@+id/tv1"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="很好吃啊" android:id="@+id/tv2"/> </LinearLayout> </LinearLayout>
UIActivity4.java
package com.hanqi.test5; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.widget.ListView; import android.widget.SimpleAdapter; import java.util.ArrayList; import java.util.Hashtable; import java.util.List; import java.util.Map; public class UIActivity4 extends AppCompatActivity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_ui4); ListView sa_1 =(ListView)findViewById(R.id.sa_1); //准备数据源 List<Map<String,Object>> lm =new ArrayList<Map<String,Object>>(); Map<String,Object> map = new Hashtable<String, Object>(); map.put("image",R.drawable.yuantu); map.put("name","美食图片01"); map.put("content","很好吃啊01"); lm.add(map); map = new Hashtable<String, Object>(); map.put("image",R.drawable.yuantu); map.put("name","美食图片02"); map.put("content","很好吃啊02"); lm.add(map); map = new Hashtable<String, Object>(); map.put("image",R.drawable.yuantu); map.put("name","美食图片03"); map.put("content","很好吃啊03"); lm.add(map); map = new Hashtable<String, Object>(); map.put("image",R.drawable.yuantu); map.put("name","美食图片04"); map.put("content","很好吃啊04"); lm.add(map); //1.数组源里key数组 String[] str ={"image","name","content"}; //2.layout文件里面子视图的id int[] viewid = {R.id.lv2,R.id.tv1,R.id.tv2,}; SimpleAdapter sa = new SimpleAdapter(this,lm,R.layout.layout_simple,str,viewid); sa_1.setAdapter(sa); } }
效果图:
相关文章推荐
- Android中AsyncTask的使用
- Android课程---关于ListView列表视图的学习
- Android课程---时间日期对话框
- 【Android基础】常用的布局和单位的简介
- Android RecyclerView实现瀑布流布局
- AndroidStudio配置NDK开发环境
- Android 高手进阶之自定义View,自定义属性(带进度的圆形进度条)
- adb logcat命令查看并过滤android输出log
- Android activity 单手操作 滑动关闭
- Android 刻度表的实现
- 流行的下拉刷新开源库
- android 创建的删除快捷图标
- Android RecyclerView添加分隔线 DividerItemDecoration
- Android 毛玻璃(高斯模糊) 开源控件。简单、快速、高效。(基于fastblur)
- 【Android基础】四种点击事件
- android,Alertdialog,自定义对话框
- Android 蓝牙开发介绍
- [Android] 对ImageView设置属性scaleType为FIT_START,如何去掉多余空白
- android对字段的验证
- 自定义view的measureSpec是谁的mode和size