zoukankan      html  css  js  c++  java
  • 怎样设置listview item选中时部分高亮?

    怎样设置listview item选中时部分高亮?
    1, 有一个现成的回调接口给选中item可用: AbsListView.SelectionBoundsAdjuster,新建一个自己的类如下:
    public class ItemHighLightScope extends LinearLayout implements SelectionBoundsAdjuster{

        TextView sortIndex;
        private static int PADDING_TOP = 0;
        
        public ItemHighLightScope(Context context, AttributeSet attrs) {
            super(context, attrs);
            // TODO Auto-generated constructor stub
        }
        
        @Override
        protected void onFinishInflate() {
            // TODO Auto-generated method stub
            try{
            super.onFinishInflate();
            sortIndex = (TextView)findViewById(R.id.date_header_text);
            }catch(Exception ex){
                ex.printStackTrace();
            }
        }

        @Override
        public void adjustListItemSelectionBounds(Rect bounds) {
            // TODO Auto-generated method stub
            if(sortIndex.getVisibility() == View.VISIBLE){
                bounds.top += (sortIndex.getHeight() + PADDING_TOP);
            }        
        }    
    }

    注意:要实现ItemHighLightScope(Context context, AttributeSet attrs) 这个构造器,否则会报错cannot inflate。
        要获得控件的view在onFinishInflate()里inflate,这时控件的view已被创建,才能被取到高度等信息。
        在adjustListItemSelectionBounds(Rect bounds)里设定高亮范围。此处的坐标应该是相对父view的。
    2, 在item的xml里,把总LinearLayout改成自己定义的类名,比如com.test.zipcategory.ItemHighLightScope。

  • 相关阅读:
    distributed caching for .net applications
    Linux_18/ mysql
    找到一本不错的Linux电子书,附《Linux就该这么学》章节目录。
    LinuxProbe/ 疑问ABC
    Linux_15/ autofs, DNS
    Linux_14/ SAMBA, NFS
    Linux_13/ 虚拟网站主机功能,Vsftpd
    Linux_12/ Apache, SELinux
    Linux_11/ firewalld-config, SSH, bounding
    Linux_10/ iptables & firewalld
  • 原文地址:https://www.cnblogs.com/lionfight/p/2881817.html
Copyright © 2011-2022 走看看