惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

The Register - Security
The Register - Security
云风的 BLOG
云风的 BLOG
U
Unit 42
F
Fortinet All Blogs
The GitHub Blog
The GitHub Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
D
Docker
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
S
Secure Thoughts
Hacker News: Ask HN
Hacker News: Ask HN
Vercel News
Vercel News
S
Security @ Cisco Blogs
GbyAI
GbyAI
Stack Overflow Blog
Stack Overflow Blog
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
I
Intezer
MongoDB | Blog
MongoDB | Blog
AI
AI
MyScale Blog
MyScale Blog
Engineering at Meta
Engineering at Meta
Y
Y Combinator Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Proofpoint News Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
W
WeLiveSecurity
博客园 - 叶小钗
S
SegmentFault 最新的问题
N
News | PayPal Newsroom
WordPress大学
WordPress大学
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
DataBreaches.Net
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
Spread Privacy
Spread Privacy
H
Help Net Security
美团技术团队
博客园 - 司徒正美
T
Threat Research - Cisco Blogs
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
K
Kaspersky official blog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
V
Vulnerabilities – Threatpost
TaoSecurity Blog
TaoSecurity Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity
J
Java Code Geeks
量子位
Martin Fowler
Martin Fowler
博客园_首页

博客园 - Game_over

零基础使用AI辅助编写易简历小程序的一些心得体会 趁五一撸个纯Flutter版的心情日记App 两个星期,用Flutter撸个APP 程序员之路:以Android证道 10天学安卓-第十天 10天学安卓-第九天 10天学安卓-第八天 10天学安卓-第七天 10天学安卓-第六天 10天学安卓-第五天 10天学安卓-第四天 10天学安卓-第三天 10天学安卓-第二天 10天学安卓-第一天 个人开发一些Android App Android 一些开源的东西 构建Android自动编译持续集成系统 Android开发视频教学资料 Android2.2 新特性
简约而不简单——Android SimpleAdapter
Game_over · 2010-06-25 · via 博客园 - Game_over

列表(ListView)、表格(GridView),这在手机应用上面肯定是少不了的,怎样实现比较复杂一点的界面呢,先看一下我的效果图。

image image

这样布局的情况是最基本的,也是最常用的,网上关于这样的布局有多种版本的实现方法,但是有很多需要自己实现Adapter,那样子是比较复杂而且没有必要的,因为我们有简约而不简单的SimpleAdapter。

1. ListView

SimpleAdapter的核心代码:

		for (int i = 0; i < 10; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("PIC", R.drawable.pic);
			map.put("TITLE", "Test Title");
			map.put("CONTENT", "Test Content");
			contents.add(map);
		}
		SimpleAdapter adapter = new SimpleAdapter(this,
				(List<Map<String, Object>>) contents, R.layout.listitem,
				new String[] { "PIC", "TITLE", "CONTENT" }, new int[] {
						R.id.listitem_pic, R.id.listitem_title,
						R.id.listitem_content });

		listView.setAdapter(adapter);

listitem的Layout:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight">
	<ImageView android:id="@+id/listitem_pic"
		android:layout_width="wrap_content" android:layout_height="fill_parent"
		android:layout_alignParentTop="true" android:layout_alignParentBottom="true"
		android:src="@drawable/pic" android:adjustViewBounds="true"
		android:padding="2dip" />
	<TextView android:id="@+id/listitem_title"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_toRightOf="@+id/listitem_pic"
		android:layout_alignParentRight="true" android:layout_alignParentTop="true"
		android:layout_above="@+id/listitem_content"
		android:layout_alignWithParentIfMissing="true" android:gravity="center_vertical"
		android:text="@+id/listitem_title" android:textSize="22px" />
	<TextView android:id="@+id/listitem_content"
		android:layout_width="fill_parent" android:layout_height="wrap_content"
		android:layout_toRightOf="@+id/listitem_pic"
		android:layout_alignParentBottom="true"
		android:layout_alignParentRight="true" android:singleLine="true"
		android:ellipsize="marquee" android:text="@+id/item_content"
		android:textSize="14px" />
</RelativeLayout>

2. GridView

SimpleAdapter的核心代码:

		for (int i = 0; i < 10; i++) {
			Map<String, Object> map = new HashMap<String, Object>();
			map.put("PIC", R.drawable.pic);
			map.put("TITLE", "Test Title");
			contents.add(map);
		}
		SimpleAdapter adapter = new SimpleAdapter(this,
				(List<Map<String, Object>>) contents, R.layout.griditem,
				new String[] { "PIC", "TITLE" }, new int[] { R.id.griditem_pic,
						R.id.griditem_title, });

		gridView.setAdapter(adapter);


griditem的Layout:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
	android:layout_height="fill_parent" android:layout_width="fill_parent"
	android:orientation="vertical">
	<ImageView android:id="@+id/griditem_pic"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_gravity="center_horizontal">
	</ImageView>
	<TextView android:id="@+id/griditem_title"
		android:layout_width="wrap_content" android:layout_height="wrap_content"
		android:layout_gravity="center_horizontal" android:text="test">
	</TextView>
</LinearLayout>

最后附上代码:https://files.cnblogs.com/game-over/test.zip