关于ListView的知识(2)

来源:互联网 发布:源码分享是什么意思 编辑:程序博客网 时间:2024/04/30 08:56
ListView的自带默认的样式其实不好用,我们可以有两种方法设置:
资源文件:
<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="bg">#66cccccc</color>
</resources>  


第一种:
ListView的工厂类
public class ListViewFactory
{
    public static ListView getListView()
    {
        ListView listView = new ListView(UIUtils.getContext());
        // 属性设置
        listView.setCacheColorHint(Color.TRANSPARENT);
        listView.setSelector(android.R.color.transparent);
        listView.setDividerHeight(0);
        listView.setScrollingCacheEnabled(false);
        listView.setBackgroundColor(UIUtils.getColor(color.bg));
        return listView;
    }
} 
第二种

public class BaseListView extends ListViewFactory
{
    public BaseListView (Context context,Attr ttrs){
    super
    init();
    }
    
     public BaseListView (Context context){
    super    
     init();
    }

       private void init(){
        // 属性设置
        setCacheColorHint(Color.TRANSPARENT);
        setSelector(android.R.color.transparent);
        setDividerHeight(0);
        setScrollingCacheEnabled(false);
        setBackgroundColor(UIUtils.getColor(color.bg));
      }
        }








0 0
原创粉丝点击