插件框架篇一之scrollbars
2016-07-23 02:10
387 查看
问题:部分手机(如三星)ListView或GridView设置scrollbars显示时会报错奔溃。
问题分析:
ScrollView继承于View,在View的构造器中初始化scrollbars。
根据initializeScrollbars判断是否需要进行scrollbars初始化,并在initializeScrollbars函数进行初始化。
在initializeScrollbars方法中有scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical四个Drawable属性的赋值。
在部分手机(如三星)系统定制过Drawable的默认值,并修改过默认资源路径,导致插件环境下无法找到相应资源报错。
解决方案:
自定义scrollbars,修改scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical属性。
1、定义scrollbars的style,并自定义scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical四个属性(一个不能漏);
2、ListView添加style;
问题分析:
ScrollView继承于View,在View的构造器中初始化scrollbars。
根据initializeScrollbars判断是否需要进行scrollbars初始化,并在initializeScrollbars函数进行初始化。
/** * <p> * Initializes the scrollbars from a given set of styled attributes. This * method should be called by subclasses that need scrollbars and when an * instance of these subclasses is created programmatically rather than * being inflated from XML. This method is automatically called when the XML * is inflated. * </p> * * @param a the styled attributes set to initialize the scrollbars from */ protected void initializeScrollbars(TypedArray a) { initScrollCache(); final ScrollabilityCache scrollabilityCache = mScrollCache; if (scrollabilityCache.scrollBar == null) { scrollabilityCache.scrollBar = new ScrollBarDrawable(); } final boolean fadeScrollbars = a.getBoolean(R.styleable.View_fadeScrollbars, true); if (!fadeScrollbars) { scrollabilityCache.state = ScrollabilityCache.ON; } scrollabilityCache.fadeScrollBars = fadeScrollbars; scrollabilityCache.scrollBarFadeDuration = a.getInt( R.styleable.View_scrollbarFadeDuration, ViewConfiguration .getScrollBarFadeDuration()); scrollabilityCache.scrollBarDefaultDelayBeforeFade = a.getInt( R.styleable.View_scrollbarDefaultDelayBeforeF 4000 ade, ViewConfiguration.getScrollDefaultDelay()); scrollabilityCache.scrollBarSize = a.getDimensionPixelSize( com.android.internal.R.styleable.View_scrollbarSize, ViewConfiguration.get(mContext).getScaledScrollBarSize()); Drawable track = a.getDrawable(R.styleable.View_scrollbarTrackHorizontal); scrollabilityCache.scrollBar.setHorizontalTrackDrawable(track); Drawable thumb = a.getDrawable(R.styleable.View_scrollbarThumbHorizontal); if (thumb != null) { scrollabilityCache.scrollBar.setHorizontalThumbDrawable(thumb); } boolean alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawHorizontalTrack, false); if (alwaysDraw) { scrollabilityCache.scrollBar.setAlwaysDrawHorizontalTrack(true); } track = a.getDrawable(R.styleable.View_scrollbarTrackVertical); scrollabilityCache.scrollBar.setVerticalTrackDrawable(track); thumb = a.getDrawable(R.styleable.View_scrollbarThumbVertical); if (thumb != null) { scrollabilityCache.scrollBar.setVerticalThumbDrawable(thumb); } alwaysDraw = a.getBoolean(R.styleable.View_scrollbarAlwaysDrawVerticalTrack, false); if (alwaysDraw) { scrollabilityCache.scrollBar.setAlwaysDrawVerticalTrack(true); } // Apply layout direction to the new Drawables if needed final int layoutDirection = getLayoutDirection(); if (track != null) { track.setLayoutDirection(layoutDirection); } if (thumb != null) { thumb.setLayoutDirection(layoutDirection); } // Re-apply user/background padding so that scrollbar(s) get added resolvePadding(); }
在initializeScrollbars方法中有scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical四个Drawable属性的赋值。
在部分手机(如三星)系统定制过Drawable的默认值,并修改过默认资源路径,导致插件环境下无法找到相应资源报错。
解决方案:
自定义scrollbars,修改scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical属性。
1、定义scrollbars的style,并自定义scrollbarThumbHorizontal、scrollbarAlwaysDrawHorizontalTrack、scrollbarTrackVertical、scrollbarThumbVertical四个属性(一个不能漏);
2、ListView添加style;
相关文章推荐
- java自动生成验证码插件-kaptcha
- jQuery插件实现文字无缝向上滚动效果代码
- jQuery菜单插件用法实例
- 加载flash9.ocx出现错误的解决方法
- jquery实现的代替传统checkbox样式插件
- 10款新鲜出炉的 jQuery 插件(Ajax 插件,有幻灯片、图片画廊、菜单等)
- jquery插件autocomplete用法示例
- 推荐40个非常优秀的jQuery插件和教程【系列三】
- Node.js插件的正确编写方式
- 推荐十款免费 WordPress 插件
- NopCommerce架构分析之(四)基于路由实现灵活的插件机制
- Bootstrap教程JS插件弹出框学习笔记分享
- Bootstrap插件全集
- 使用JavaScript开发IE浏览器本地插件实例
- jQuery实现的简单提示信息插件
- 推荐25个超炫的jQuery网格插件
- 纯JavaScript实现的分页插件实例
- JQuery插件jcarousellite的参数中文说明
- Bootstrap Paginator分页插件使用方法详解
- Bootstrap每天必学之弹出框(Popover)插件