• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >Android > Android UI:ListView,androiduilistview

Android UI:ListView,androiduilistview

作者:网友 字体:[增加 减小] 来源:互联网 时间:2017-05-26

网友通过本文主要向大家介绍了android ui listview,android 横向listview,android listview,android中listview,android 水平listview等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

Android UI:ListView,androiduilistview


SimpleAdapter是扩展性最好的适配器,可以定义各种你想要的布局,而且使用很方便。

layout :

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="horizontal">
 6         <ListView
 7             android:layout_width="match_parent"
 8             android:layout_height="wrap_content"
 9             android:divider="#7f00"    //分割线
10             android:dividerHeight="2dp"
11             android:id="@+id/listview_sample"/>
12 </LinearLayout>

header layout:

1 <?xml version="1.0" encoding="utf-8"?>
2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
3 android:orientation="vertical" android:layout_width="match_parent"
4 android:layout_height="match_parent">
5 <ImageView
6     android:layout_width="match_parent"
7     android:layout_height="wrap_content"
8     android:src="@mipmap/ic_launcher"/>
9 </LinearLayout>

 

 

自定义布局  item:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="horizontal">
 6     <ImageView
 7         android:layout_width="wrap_content"
 8         android:layout_height="wrap_content"
 9         android:layout_margin="3px"
10         android:id="@+id/img"/>
11     <LinearLayout
12         android:layout_width="match_parent"
13         android:layout_height="wrap_content"
14         android:orientation="vertical">
15         <TextView
16             android:layout_width="match_parent"
17             android:layout_height="wrap_content"
18             android:textSize="16sp"
19             android:id="@+id/title"/>
20         <TextView
21             android:layout_width="match_parent"
22             android:layout_height="wrap_content"
23             android:id="@+id/info"
24             android:textSize="16sp"/>
25     </LinearLayout>
26 
27 </LinearLayout>

 

 

Java 代码:

 1 public class SampleAdapterActivity extends Activity {
 2 
 3     private ListView mListview;
 4     @Override
 5     protected void onCreate(Bundle savedInstanceState) {
 6         super.onCreate(savedInstanceState);
 7         setContentView(R.layout.sampleadapter_layout);
 8         mListview = (ListView) findViewById(R.id.listview_sample);
 9         SimpleAdapter adapter = new SimpleAdapter(this,
10                 getData(),  //数据来源
11                 R.layout.item_listview, //对应item view
12                 new String[]{"img","title","info"}, //data 中对应值
13                 new int[]{R.id.img,R.id.title,R.id.info});  //填充layout位置
14         mListview.setHeaderDividersEnabled(true);      //是否显示头view 的分割线
15         View header = View.inflate(this,R.layout.listview_header,null);
16         View footer = View.inflate(this,R.layout.listview_header,null);
17         mListview.addHeaderView(header);    //添加头部view
18         mListview.addFooterView(footer);     //添加底部view
19         mListview.setAdapter(adapter);
20     }
21 
22     @Override
23     protected void onResume() {
24         super.onResume();
25     }
26     private List<? extends Map<String,?>> getData() {
27         List<Map<String,Object>> items = new ArrayList<Map<String, Object>>();
28         for (int i = 0; i < 5; i++) {
29             Map<String,Object> item = new HashMap<String,Object>();
30             item.put("img",R.mipmap.ic_launcher);
31             item.put("title","title -- " + i );
32             item.put("info","info -- " + i );
33             items.add(item);
34         }
35         return items;
36     }
37 }

 显示效果

 

 

分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • Android UI:ListView,androiduilistview
  • Android UI ListView的使用,androidlistview

相关文章

  • 2017-05-26DroidPlugin插件化开发,droidplugin插件
  • 2017-05-26android:px,dp(dip),sp的区别
  • 2017-05-26银联支付,支付
  • 2017-05-26android注册页面,android页面
  • 2017-05-26Mac版 Android Studio快捷键大全,android快捷键大全
  • 2017-05-26向android studio中导入带有jni的eclipse项目
  • 2017-05-26Android—Service与Activity的交互,androidactivity
  • 2017-05-26一个规范的自定义View——Android开发艺术探索笔记
  • 2017-05-26[android] 手机卫士界面切换动画,android卫士
  • 2017-05-26Android Studio NDK基础使用

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • (试笔)一、Android四大框架之ContentProvider的学习与运用,实现SQLite的增删改查。,安卓sqlite增删改查
    • Android系统四层架构分享,android四层架构
    • golang错误处理之error
    • 浅谈Android编码规范及命名规范,浅谈android编码规范
    • 浅谈Android应用保护(一):Android应用逆向的基本方法,浅谈android
    • 在Mac系统中 下载、安装AndroidStudio
    • 和我一起看API(一)你所不知道的LinearLayout补充,apilinearlayout
    • Fragment,androidfragment
    • android开发游记:meterial design 5.0 新增控件介绍及使用方法
    • Android Gson使用入门及GsonFormat插件的使用

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有