android中listview中设计左图标
2013-07-01 17:44
302 查看
在listview中,如果做成一个象下图那样的列表,每个列表项的前面有一个小的图形呢?
比如如下图:
可以这样做:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp">
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:divider="@null"/>
</LinearLayout>
listview中每个项的样式文件
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/itemText"
android:drawableLeft="@drawable/bullet"
android:drawablePadding="8dp"
android:padding="5dp"
android:textSize="20sp"
android:text="List Item"/>
注意这里是android:drawableLeft="@drawable/bullet"
指定了左边的小图形是在drawable目录下的bullet.xml中的样式
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="6dp"
android:height="6dp"/>
<solid
android:color="#FF00F0"/>
</shape>
最后的主程序
比如如下图:
可以这样做:
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="10dp">
<ListView
android:id="@+id/listView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:listSelector="@android:color/transparent"
android:divider="@null"/>
</LinearLayout>
listview中每个项的样式文件
list_item.xml
<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/itemText"
android:drawableLeft="@drawable/bullet"
android:drawablePadding="8dp"
android:padding="5dp"
android:textSize="20sp"
android:text="List Item"/>
注意这里是android:drawableLeft="@drawable/bullet"
指定了左边的小图形是在drawable目录下的bullet.xml中的样式
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size
android:width="6dp"
android:height="6dp"/>
<solid
android:color="#FF00F0"/>
</shape>
最后的主程序
public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); GetArrayList();//获得一个列表数组,比如得到一个listCountry数组 ListView listView = (ListView)findViewById(R.id.listView); listView.setAdapter(new ArrayAdapter<String>( this, R.layout.list_item, listCountry)); }
相关文章推荐
- 关于android图标美工设计尺寸与处理方法
- Android--MVP架构设计Listview
- Android可视化开发工具,包括设计GUI,图标ICON,字体等的工具集合
- Android布局设计之ListView使用XML数据源来分页加载
- Android MVP设计框架模板 之 漂亮ListView上拉刷新下拉加载更多
- Android改变ExpandableListView的indicator图标实现方法
- Android中利用ListView和GridView实现列表视图和网格(图标)视图的相互切换显示
- Android UI 设计(12):ListView 练习(制作水果选择菜单)
- android listview用adapter.notifyDataSetChanged()无法刷新每项的图标
- Android设计 - 图标设计概述(Iconography)
- android设计,图标等概述
- 【Android开发】范例2-实现带图标的ListView
- 【Android】字体和图标大小设计规范
- 浅谈Android系统的图标设计规范
- Android设计应用图标不用愁---Asset Studio Integration来帮你
- 怎样更好的设计android图标,拉伸不变形等等系列长处,并且减小apk大小
- Android快速开发之设计通用的ListView,GridView的适配器
- Android设计 - 图标设计概述(Iconography)
- Android UI 设计(11):ListView 控件使用优化(五)
- 教你如何给Android产品设计一款合适的图标