android中listview中设计左图标
来源:互联网 发布:档案制作软件 编辑:程序博客网 时间:2024/06/07 10:43
在listview中,如果做成一个象下图那样的列表,每个列表项的前面有一个小的图形呢?
比如如下图:
[img]
http://pareshnmayani.files.wordpress.com/2011/11/bulleted-listview.png
[/img]
可以这样做:
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>
最后的主程序
比如如下图:
[img]
http://pareshnmayani.files.wordpress.com/2011/11/bulleted-listview.png
[/img]
可以这样做:
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中listview中设计左图标
- Android Market中产品图标设计原则
- 在ListView中加入图标
- Android中ListView条目带有左滑显示删除按钮的总结
- C#中ListView添加系统文件图标
- C#中ListView添加系统文件图标
- ListView 图标显示在subitem中
- ListView 图标显示在subitem中
- bcb 在ListView中显示图标
- Android 中ListView 嵌套 ListView
- Android listview 中嵌套 listview
- Android中自定义ListView
- Android中ListView分类
- android中使用listview
- android中ListView介绍
- Android中ListView分类
- Android中ListView应用
- Android中自定义ListView
- 推荐一个不错的讲云的BLOG
- ror学习小结6
- jquery ui 1.8.6的日期器中存在内存泄露
- ( 转)关于Android的nodpi,xhdpi,hdpi,mdpi,ldpi
- (转)用php解析html
- android中listview中设计左图标
- android中判断sd卡是否准备好
- PinyinIME输入法开发
- (转)MySQL 数据库性能优化之缓存参数优化
- Android中获得SD卡中的值
- java中的finally小结收藏
- 红绿灯检测
- android中校验email是否合法
- 【Spring中用到的设计模式】