Android ListView圆角
首先来看看ListView 相关基本属性
1、单击列表后,列表的背景变成黑色了。
可通过指定android:cacheColorHint的属性来放变它,将它指定为透明。
使用以下的属性值:
android:cacheColorHint="#000000" 就可以。
2、去除列表项中间的切割线:android:divider="#00000000",这里的值也能够指向一个drawable图片对象(android:divider="@drawable/list_line")。假设使用了图片高度大于系统的像素的话,能够自己设定一个高度。
android:dividerHight="10px"
3、listview在拖动时。listview的背景变成黑色。用这个可解决:android:scrollingCache="false"
4、listview的上边和下边有黑色的阴影。用这个可解决:android:fadingEdge="none"
5、listview右边的滑动条覆盖列表项的内容。用这个可解决:android:scrollbarStyle="outsideInset"
6、改动listvew右边的滑动条与列表项之间的距离。
用这个可解决:android:paddingRight="10dip"。能够依据须要进行改动。
7、改动右边的滑动条显示的颜色。用这个可解决:
android:scrollbarTrackVertical="@drawable/scrollbar_vertical_track"
android:scrollbarThumbVertical="@drawable/scrollbar_vertical_thumb"
当中scrollbar_vertical_track和scrollbar_vertical_thumb是滑动条的XML配置文件,在API中有,可依据自己的须要改动一下開始颜色和结束颜色就可以。
详细请參考这篇文章Android ListView 属性
以下来看看ListView 圆角实现,本文主要亮点是数据源能够灵活设置。不用在xml上写死了。
1.在drawable文件下新建
list_bottom_selector.xml
<? xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<solid android:color="#ADFF2F" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" />
</shape></item>
<item><shape>
<solid android:color="@color/white" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp" />
</shape></item> </selector>
如法炮制 新建几个xml
list_rect_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<solid android:color="#ADFF2F" />
</shape></item>
<item><shape>
<solid android:color="@color/white" />
</shape></item> </selector>
list_round_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<solid android:color="#ADFF2F" />
<corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp"
android:topLeftRadius="4dp" android:topRightRadius="4dp"/>
</shape></item>
<item><shape>
<solid android:color="@color/white" /> <corners android:bottomLeftRadius="4dp" android:bottomRightRadius="4dp"
android:topLeftRadius="4dp" android:topRightRadius="4dp"/>
</shape></item> </selector>
list_top_selector.xml
<?xml version="1.0" encoding="utf-8"? >
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_pressed="true"><shape>
<solid android:color="#ADFF2F" /> <corners android:topLeftRadius="4dp" android:topRightRadius="4dp" />
</shape></item>
<item><shape> <solid android:color="@color/white" /> <corners android:topLeftRadius="4dp" android:topRightRadius="4dp" />
</shape></item> </selector>
接下来我们在layout新建一个item.xml
<?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="wrap_content"
android:paddingRight="5dp"
>
<TextView
android:id="@+id/text"
android:layout_width="fill_parent"
android:layout_height="40dp"
android:textSize="16sp"
android:paddingLeft="15dp"
android:textColor="#000000"
android:gravity="left|center_vertical"
/> <ImageView
android:src="@drawable/common_left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
/> </RelativeLayout>
后新建一个activity_main.xml 来作为我们程序的主页面。也就是我们要显示ListView,布局也非常easy
例如以下:
<?xml version="1.0" encoding="utf-8"? >
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:paddingTop="15dp" > <ListView
android:id="@+id/list1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/round_bg"
android:cacheColorHint="#00000000"
android:divider="@color/list_divider"
android:dividerHeight="0.1dp"
android:listSelector="#00000000" >
</ListView> <ListView
android:id="@+id/list2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/round_bg"
android:cacheColorHint="#00000000"
android:divider="@color/list_divider"
android:dividerHeight="0.1dp"
android:listSelector="#00000000" >
</ListView> <ListView
android:id="@+id/list3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
android:background="@drawable/round_bg"
android:cacheColorHint="#00000000"
android:divider="@color/list_divider"
android:dividerHeight="1px"
android:listSelector="@color/transparent" >
</ListView>
</LinearLayout>
然后新建一个MainActivity
public class MainActivity extends Activity {
private ListView list1;
private ListView list2;
private ListView list3;
String array1[] = {"设置"};
String array2[] = {"朋友圈","我的空间"};
String array3[] = {"我的钱包","我的收藏","我的相冊","关联"};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
initView();
}
private void initView()
{
list1 = (ListView) findViewById(R.id.list1);
list2 = (ListView) findViewById(R.id.list2);
list3 = (ListView) findViewById(R.id.list3);
list1.setAdapter(new MyListAdapter(array1,this));
list2.setAdapter(new MyListAdapter(array2,this));
list3.setAdapter(new MyListAdapter(array3,this));
}
}
后面我们自己定义一个MyListAdapter 继承BaseAdapter
public class MyListAdapter extends BaseAdapter {
private LayoutInflater inflater;
private String[] array;
private Context mContext;
public MyListAdapter(String[] array,Context context) {
inflater = LayoutInflater.from(context);
this.array = array;
this.mContext =context;
}
@Override
public int getCount() {
// TODO Auto-generated method stub
return array.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return array[position];
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
convertView = inflater.inflate(R.layout.item, null);
TextView tv = (TextView) convertView.findViewById(R.id.text);
tv.setText(array[position]);
if (array.length == 1) {
setBackgroundDrawable(convertView,
R.drawable.list_round_selector);
} else if (array.length == 2) {
if (position == 0) {
setBackgroundDrawable(convertView,
R.drawable.list_top_selector);
} else if (position == array.length - 1) {
setBackgroundDrawable(convertView,
R.drawable.list_bottom_selector);
}
} else {
if (position == 0) {
setBackgroundDrawable(convertView,
R.drawable.list_top_selector);
} else if (position == array.length - 1) {
setBackgroundDrawable(convertView,
R.drawable.list_bottom_selector);
} else {
setBackgroundDrawable(convertView,
R.drawable.list_rect_selector);
}
}
return convertView;
}
private void setBackgroundDrawable(View view, int resID) {
view.setBackgroundDrawable(mContext.getResources().getDrawable(resID));
}
}
效果图:
Android ListView圆角的更多相关文章
- Android中实现ListView圆角效果[转]
本文演示如何Android中实现ListView圆角效果. 无论是网站,还是APP,人们都爱看一些新颖的视图效果.直角看多了,就想看看圆角,这几年刮起了一阵阵的圆角设计风:CSS新标准纳入圆角元素,特 ...
- Android ListView各种效果实现总结,持续更新...
一.ListView圆角:重写ListView的onInterceptTouchEvent方法,通过pointToPosition(x,y)方法判断当前点击位置所对应的项,有三种情况:分别是第一项.最 ...
- android ListView 九大重要属性详细分析、
android ListView 九大重要属性详细分析. 1.android ListView 一些重要属性详解,兄弟朋友可以参考一下. 首先是stackFromBottom属性,这只该属性之后你做好 ...
- Android ListView onItemClick Not Work
Android ListView onItemClick Not Work ListView item中有Button和RadioButton的时候,它的Item点击事件不起作用,需要设置item的属 ...
- 【腾讯Bugly干货分享】Android ListView与RecyclerView对比浅析--缓存机制
本文来自于腾讯bugly开发者社区,非经作者同意,请勿转载,原文地址:http://dev.qq.com/topic/5811d3e3ab10c62013697408 作者:黄宁源 一,背景 Recy ...
- Android ListView 常用技巧
Android ListView 常用技巧 Android TextView 常用技巧 1.使用ViewHolder提高效率 ViewHolder模式充分利用了ListView的视图缓存机制,避免了每 ...
- Android listview addHeaderView 和 addFooterView 详解
addHeaderView()方法:主要是向listView的头部添加布局addFooterView()方法:主要是向listView的底部添加布局 需要注意的是添加布局的时候应该添加从父容器开始添加 ...
- Android ListView滑动过程中图片显示重复错乱闪烁问题解决
最新内容建议直接访问原文:Android ListView滑动过程中图片显示重复错乱闪烁问题解决 主要分析Android ListView滚动过程中图片显示重复.错乱.闪烁的原因及解决方法,顺带提及L ...
- Android --ListView分页
参考博客:Android ListView分页加载(服务端+android端)Demo 监听OnScrollListener事件 class OnListScrollListener implemen ...
随机推荐
- 通过分区(Partitioning)提高Spark的运行性能
在Sortable公司,很多数据处理的工作都是使用Spark完成的.在使用Spark的过程中他们发现了一个能够提高Sparkjob性能的一个技巧,也就是修改数据的分区数,本文将举个例子并详细地介绍如何 ...
- RSS是什么,RSS怎么玩,RSS原理是什么 (zhuan)
http://www.cjjjs.com/paper/gzsh/201622721397372.aspx *********************************************** ...
- VBA学习笔记(2)--新建word文档并插入文字
说明(2017.3.20): 1. Dim As声明变量类型,Set赋值/初始化 2. With使后面的省略对象,直接点就行,后面要End With 3. Application.StatusBar ...
- 个推-推送hello world
最近项目中的一个百度推送真是把我搞的有点头大,真的是很垃圾,到达率又低,还特么遇上停止维护了... 所以项目决定转用别的推送平台,现在改用个推,官方文档写的很好,除了刚下载下来,折腾了一阵子,不过很快 ...
- buildroot 文件系统添加telnet, ssh, 以及制作注意事项
buildroot 制作Linux嵌入式文件系统,并添加telnet 以及ssh * sshd 服务的添加 // make menuconfig Target options ---> Targ ...
- 一站式学习Wireshark(十):应用Wireshark显示过滤器分析特定数据流(下)
介绍 掌握显示过滤器对于网络分析者来说是一项必备的技能.这是一项大海捞针的技巧.学会构建,编辑,保存关键的显示过滤器能够节省数小时的时间. 与捕捉过滤器使用的BPF语法不同,显示过滤器使用的是Wire ...
- wso2as安装
1.系统环境 Ubuntu12.04 192.168.0.97 root/password找管理员 Ubuntu12.04 192.168.0.99 root/password ...
- sysctl -p 重新加载文件/etc/sysctl.conf -a 所有参数 -w 临时指定
sysctl命令用于运行时配置内核参数,这些参数位于/proc/sys目录下.sysctl配置与显示在/proc/sys目录中的内核参数.可以用sysctl来设置或重新设置联网功能,如IP转发.IP碎 ...
- Linux mysql5.5
1.假设已经有mysql-5.5.10.tar.gz以及cmake-2.8.4.tar.gz两个源文件 (1)先安装cmake(mysql5.5以后是通过cmake来编译的) [root@ rhel5 ...
- R语言基于S4的面向对象编程
前言 本文接上一篇文章 R语言基于S3的面向对象编程,本文继续介绍R语言基于S4的面向对象编程. S4对象系统具有明显的结构化特征,更适合面向对象的程序设计.Bioconductor社区,以S4对象系 ...