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。

  • 相关阅读:
    深入剖析RocketMQ源码-NameServer
    Percolator模型及其在TiKV中的实现
    源码解读Dubbo分层设计思想
    vivo营销自动化技术解密|开篇
    Node.js 应用全链路追踪技术——[全链路信息获取]
    Linux系统 usermod -a -G 不重启 立即生效
    安装Docker和Docker-Compose工具
    linux 启动停止jar
    check_ffmpeg_status
    shell 的字符完全匹配
  • 原文地址:https://www.cnblogs.com/lionfight/p/2881817.html
Copyright © 2011-2022 走看看