- 浏览: 298385 次
- 性别:
- 来自: 上海
最新评论
-
再_见孙悟空:
写的不错
Dialog -
a549262189:
支持下,正好在学习这块的内容!
Android Gesture Detector -
dcsff:
受教了
LayoutInflater -
庆_啊:
真厉害。
LayoutInflater -
ghj234:
学习了,哈哈
LayoutInflater
1. ListView with Icon
(1)效果图
(2)实现代码
1)listview.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent"> <ListView android:id="@+id/listview" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout>
2)simple_list_item_icon.xml
<?xml version="1.0" encoding="UTF-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content"> <ImageView android:id="@+id/simple_list_item_icon_iv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:baselineAlignBottom="true"> </ImageView> <TextView android:id="@+id/simple_list_item_icon_tv" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="24dip"> </TextView> </LinearLayout>
3)IconSimpleAdapter.java
public class IconSimpleAdapter extends BaseAdapter { private LayoutInflater mInflater; private List<Map<String, Object>> mList; private String[] mIndex; public IconSimpleAdapter(Context context, String[] index, List<Map<String, Object>> list) { mInflater = LayoutInflater.from(context); mList = list; mIndex = index; } @Override public int getCount() { return mList.size(); } @Override public Object getItem(int position) { return mList.get(position); } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolder holder = null; if (convertView == null) { Bitmap mIcon = (Bitmap) mList.get(position).get(mIndex[0]); String mItem = " " + (String) mList.get(position).get(mIndex[1]); convertView = mInflater.inflate(R.layout.simple_list_item_icon, null); holder = new ViewHolder(); holder.text = (TextView) convertView.findViewById(R.id.simple_list_item_icon_tv); holder.icon = (ImageView) convertView.findViewById(R.id.simple_list_item_icon_iv); holder.text.setText(mItem); holder.icon.setImageBitmap(mIcon); convertView.setTag(holder); } else { holder = (ViewHolder) convertView.getTag(); } return convertView; } private class ViewHolder { TextView text; ImageView icon; } }
4)IconListActivity.java
public class IconListActivity extends Activity { private final String ITEM_ICON = "icon"; private final String ITEM_TEXT = "text"; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.listview); List<Map<String, Object>> data = new ArrayList<Map<String, Object>>(); Map<String, Object> item = new HashMap<String, Object>(); Bitmap bm1 = BitmapFactory.decodeResource(getResources(), R.drawable.a); item.put(ITEM_ICON, bm1); item.put(ITEM_TEXT, "中秋节"); data.add(item); item = new HashMap<String, Object>(); Bitmap bm2 = BitmapFactory.decodeResource(getResources(), R.drawable.b); item.put(ITEM_ICON, bm2); item.put(ITEM_TEXT, "端午节"); data.add(item); item = new HashMap<String, Object>(); Bitmap bm3 = BitmapFactory.decodeResource(getResources(), R.drawable.c); item.put(ITEM_ICON, bm3); item.put(ITEM_TEXT, "重阳节"); data.add(item); item = new HashMap<String, Object>(); Bitmap bm4 = BitmapFactory.decodeResource(getResources(), R.drawable.d); item.put(ITEM_ICON, bm4); item.put(ITEM_TEXT, "清明节"); data.add(item); ListView lv = (ListView) findViewById(R.id.listview); IconSimpleAdapter adapter = new IconSimpleAdapter(this, new String[] {ITEM_ICON, ITEM_TEXT}, data); lv.setAdapter(adapter); } }
2. ListView with 3Rows
(1)效果图
(2)实现代码
1)hs_activity.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="fill_parent" android:id="@+id/hs_linearlayout"> <ListView android:id="@+id/hs_activity_lv" android:layout_width="fill_parent" android:layout_height="fill_parent" /> </LinearLayout>
2)simple_list_item_3.xml
<?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"> <TextView android:id="@+id/simple_list_item_3_tv1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="10dip"/> <TextView android:id="@+id/simple_list_item_3_tv2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="18dip"/> <TextView android:id="@+id/simple_list_item_3_tv3" android:layout_width="wrap_content" android:layout_height="wrap_content" android:textSize="12dip"/> </LinearLayout>
3)ThreeRowsListActivity.java
public class ThreeRowsListActivity extends Activity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.hs_activity); List<Map<String, Object>> data = new ArrayList<Map<String,Object>>(); Map<String, Object> item = new HashMap<String, Object>(); item.put("category", "便民,超市"); item.put("name", "中百超市"); item.put("address", "武汉街道口2547号"); data.add(item); item = new HashMap<String, Object>(); item.put("category", "五星级酒店"); item.put("name", "希尔顿大酒店"); item.put("address", "上海宝山路3651号"); data.add(item); item = new HashMap<String, Object>(); item.put("category", "写字楼,办公"); item.put("name", "中环假日酒店"); item.put("address", "北京菜户营1号"); data.add(item); ListView listView = (ListView) findViewById(R.id.hs_activity_lv); ListAdapter adapter = new SimpleAdapter(this, data, R.layout.simple_list_item_3, new String[] {"category", "name", "address"}, new int[] {R.id.simple_list_item_3_tv1, R.id.simple_list_item_3_tv2, R.id.simple_list_item_3_tv3}); listView.setAdapter(adapter); } }
3. ListView with Icon
(1)How to get android default icons
1)http://www.darshancomputing.com/android/1.5-drawables.html
2)android.jar
(2)Classic Code
1)main.xml
<?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"> <ListView android:id="@id/android:list" android:layout_width="fill_parent" android:layout_height="fill_parent" android:layout_weight="1" android:drawSelectorOnTop="false" /> </LinearLayout>
2)row.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/vw1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:orientation="horizontal"> <ImageView android:id="@+id/img" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical"> <TextView android:id="@+id/text1" android:textSize="12sp" android:textStyle="bold" android:layout_width="fill_parent" android:layout_height="wrap_content"/> <TextView android:id="@+id/text2" android:textSize="12sp" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </LinearLayout> </LinearLayout>
3)ResourceExplorer.java
public class ResourceExplorer extends ListActivity { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // define the list which holds the information of the list List<Map<String, Object>> resourceNames = new ArrayList<Map<String, Object>>(); // define the map which will hold the information for each row Map<String, Object> data; // hard coded numbers retrieved from // http://code.google.com/android/reference/android/R.drawable.html for (int idx = 17301504; idx <= 17301655; idx++) { data = new HashMap<String, Object>(); try { String stg = Resources.getSystem().getResourceName(idx); data.put("line1", stg); data.put("line2", idx); data.put("img", idx); resourceNames.add(data); } catch (Resources.NotFoundException nfe) { } } SimpleAdapter notes = new SimpleAdapter(this, resourceNames, R.layout.row, new String[] { "line1", "line2", "img" }, new int[] { R.id.text1, R.id.text2, R.id.img }); setListAdapter(notes); } }
4.
发表评论
-
如果在Eclipse中debug
2010-05-02 14:15 0最基本的操作是: 1, 首先在一个java文件中设断点,然后 ... -
How to download sourcecode of android with cygwin
2010-04-14 16:07 5115cygwin是一个在windows平台 ... -
TelephoneManager
2010-03-08 16:04 01. protected void onCreate(Bun ... -
eclipse c
2010-03-07 21:05 0Eclipse 除 了可以开发Java之外,还支持了许 ... -
android sdk安装
2010-02-02 23:37 34901.下载:http://developer.android.c ... -
google map my demo
2010-02-02 23:36 3202<uses-library android:name=& ... -
Toast
2010-02-02 23:35 14791. (1) public class ToastActi ... -
如何在MapView上画图
2010-02-02 23:34 1585http://ophone8.com/thread-4340- ... -
Service
2010-02-02 23:33 31571. Service生命周期 (1)Servic ... -
Notification
2010-02-02 23:33 19381. Notification构造器的参数 分别为: ... -
导航相关概念
2010-02-02 23:32 17031. Google Map的定位 (1)Goog ... -
PendingIntent和Intent
2010-02-02 23:28 9531Notification n = new Notificati ... -
Broadcast调用Service做的一个定时器
2010-02-02 23:28 37141. public class AlarmActivity ... -
Broadcast Receiver
2010-02-02 23:27 8695Broadcast Receiver用于接收并处理广播通知(b ... -
LayoutInflater
2010-02-02 23:27 21813一般来讲,我们用LayoutInflater做一件事:infl ... -
Android's Components 生命周期
2010-02-02 23:27 2166Android中,Component(activity、ser ... -
Activity文档翻译
2010-02-02 23:26 1604转自:http://www.blogjava.net/m ... -
Intent
2010-01-20 10:51 011 public class MumActivity ex ... -
aidl
2010-01-05 11:24 30661. android进程之间如何通讯呢(在不同的进程中怎样传递 ... -
Gallery 画廊
2009-12-17 20:25 33811. images.xml <?xml ver ...
相关推荐
Customize connectivity view (colors / text / layout) Customize empty view Customize progress view Customize error view PR TODOS Why this layout A very common flow of an android view is : show a ...
-- Customize your theme here. --> <item name="colorPrimary">@color/colorPrimary <item name="colorPrimaryDark">@color/colorPrimaryDark <item name="colorAccent">@color/colorAccent ...
4,QML-Customize-Flipable QML实现页面反转封装,旋转过程中修改页面不透明度,比例,角度 5. QML-ListView-header-Suspension QML实现ListView控件悬浮标题栏 6,QML-Reflection QML实现控件或图片倒影效果 ...
> Please refer to Android docs to customize lists depending on your needs. ATableView Summary ATableView intends to imitate same object model proposed on UIKit for building tables, so it's not only ...
Memo, Edit, ListView and other components support transparent background, the border effect can be customized, add the commonly used search box and password input box. Redefined Toolbar, showing very...
在别人源码基础上提取写的一个组件化android应用的框架,实现了组件化的HeaderBar,TabBar,SlideGallery,LIstView,TabView,WebView和TabHost,还包括版本检查和内嵌广告的功能。
Column Handler - Add Columns to Explorer‘s Listview in Win2k/WinME and greater.ExtractIcon Handler - Change Shell object Icons to use your own.IconOverlay Handler - Add Custom Overlay images to ...
在Android应用开发中,夜间模式是一项重要的功能,它允许用户在低光照环境下或者个人喜好时...这种方法不仅支持ListView和RecyclerView,而且能够确保界面元素在主题切换时正确更新颜色,为用户提供良好的视觉体验。
SelectionDrawParams property is added in DBGridEh and DBVertGridEh component, which allows you to customize the style of the currently selected cell. The property has the following sub-properties: ...
对于包含可滚动内容的视图(如ScrollView或ListView),你需要在布局文件中添加`android:fitsSystemWindows="true"`属性,以确保内容正确填充到状态栏下方,同时设置`android:clipToPadding="false"`防止内容被裁剪...