文章标题

来源:互联网 发布:国外健身社交软件 编辑:程序博客网 时间:2024/06/05 12:06

Android轮播控件 ImageSlider+PagerIndicator
遇到的问题:

1.指示器背景是一个灰色的条幅,实际中不让出现
2.指示器shape为Rectangle,并且要求有一个灰色边框

解决:

对于第一个问题

不能使用TextSliderView,要用DefaultSliderView

DefaultSliderView defaultSliderView=new DefaultSliderView(context);//创建对象defaultSliderView.image(list.get(i));//放置图片资源(网络本地都可以)mSliderLayout.addSlider(defaultSliderView);//添加到sliderlayout

对于第二个问题
既然要加边框,必然要用自定义的指示器,在布局中添加指示器控件,所以在drawable文件夹下创建了shape(选中和未选中的)

custom:selected_drawable="@drawable/indicator_selected"          custom:unselected_drawable="@drawable/indicator_unselected"

再给大家看一下shape中的内容 indicator_selected

<shape xmlns:android="http://schemas.android.com/apk/res/android">    <solid android:color="@color/colorWhite"/>    <stroke android:width="@dimen/x2"        android:color="@color/colorGray"/></shape>

但是这种没出来效果,很困惑,找了很多博客没有解决,最后在daimajia的GitHub上找到了问题所在

请注意:因为一个自定义的图像用于指示,以下属性不会工作:custom:selected_colorcustom:selected_widthcustom:selected_heightcustom:shapecustom:colorcustom:widthcustom:height那个selected_drawableunselected_drawable就是自定义图像,宽高无法工作自然不会有效果,所以只能找美工要了选中和未选中的图片
custom:selected_drawable="@mipmap/indicator_selected"            custom:unselected_drawable="@mipmap/indicator_unselected"

希望对大家有所帮助!

原创粉丝点击