展会信息港展会大全

RelativeLayout+ListView android开发学习
来源:互联网   发布日期:2015-11-26 11:02:49   浏览:2229次  

导读:效果图public class ListViewActivity extends ListActivity{/** Called when the activity is first created. */@Overridepublic void onCreate(Bundle savedInstanceState){super.onCreate(sav......

效果图

public class ListViewActivity extends ListActivity

{

/** Called when the activity is first created. */

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

// setContentView(R.layout.main);

SimpleAdapter adapter = new SimpleAdapter(this, getData(),

R.layout.main, new String[]

{"title","info","img"}, new int[]

{ R.id.title, R.id.info, R.id.img });

setListAdapter(adapter);

}

private List<Map<String, Object>> getData()

{

List<Map<String, Object>> list = new ArrayList<Map<String, Object>>();

Map<String, Object> map = new HashMap<String, Object>();

map.put("title", "G1");

map.put("info", "google 1");

map.put("img", R.drawable.icon);

list.add(map);

map = new HashMap<String, Object>();

map.put("title", "G2");

map.put("info", "google 2");

map.put("img", R.drawable.icon);

list.add(map);

map = new HashMap<String, Object>();

map.put("title", "G3");

map.put("info", "google 3");

map.put("img", R.drawable.icon);

list.add(map);

return list;

}

}

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

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

android:orientation="vertical" android:layout_width="fill_parent"

android:layout_height="fill_parent">

<RelativeLayout

android:orientation="vertical"

android:layout_width="wrap_content"

android:layout_height="wrap_content">

<ImageView

android:id="@+id/img"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_margin="2px"/>

<TextView

android:id="@+id/title"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_toRightOf="@id/img"

android:textColor="#FFFFFFFF"

android:textSize="22px" />

<TextView

android:id="@+id/info"

android:layout_toRightOf="@id/img"

android:layout_alignBottom="@id/img"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#FFFFFFFF"

android:textSize="13px" />

</RelativeLayout>

</LinearLayout>

ListActivity下有setListAdapter()方法

// ListView 中某项被选中后的逻辑

@Override protected void onListItemClick(ListView l, View v, int position, long id) { Log.v("MyListView4-click", (String) mData.get(position).get("title")); }

赞助本站

人工智能实验室

相关热词: RelativeLayout

AiLab云推荐
推荐内容
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港