android gallery 自定义边框+幻灯片
16lz
2021-01-26
最近在项目中用到图片轮播,试了Gallery,ViewFlipper,ViewPager,感觉Gallery最符合需求,但是Gallery的系统边框很难看,项目中要求用自己的背景图片。
下面来看一下使用Gallery实现图片轮播
运行效果:
布局文件:
[java] view plain copy- <FrameLayout
- >
- />
- >
- />
- />
- />
- </FrameLayout>
其中,android:fadingEdge="none"消除图片两边的阴影。使用FrameLayout在底部显示小圆点
[java] view plain copy- publicclassextends private privateint;
- private
- privatestaticfinalint;
- publicvoid super ].setImageDrawable(getBaseContext().getResources()
- newthis new ,);
- privatevoid new privatenew
- publicvoid new ;
- *开一个线程执行耗时操作
- */ privatenew
- publicvoid super switch case:
- break default break *设置小圆点显示,position会一直增加,如果要循环显示图片,需要对position取余,否则数组越界
- */ privatenew
- publicvoid intlong int if){
- ].setImageDrawable(getBaseContext()
- if)){
- ].setImageDrawable(getBaseContext()
- if){
- ]
- publicvoid
- *点击事件,点击图片进入SecondActivity
- */ privatenew
- publicvoidint long new thisclass }
ImageAdapter类,重写android.widget.BaseAdapter,用于描述图像信息。
- publicclassextends private privateint privatestaticfinalint;
- public this
- publicint return
- publicint return
- publiclongint return
- publicint new new new ,,,);
- return }
如果用系统背景,可以这样写
- int private public //获得Gallery组件的属性 );
- }
在getview中设置
[java] view plain copy- imageView.setBackgroundResource(mGalleryItemBackground);
Gallery组件属性信息定义在res\values\attrs.xml
[java] view plain copy- <?xmlversion=encoding=?>
- >
- />
- </resources>
更多相关文章
- Android保存图片到相册
- Android(安卓)InputMethod 源码分析,显示输入法流程
- Android下载的视频,在相册中显示
- 修改checkbox框颜色
- Building Custom Components/建立自定义组件
- 小记 ScrollView 隐藏 里面空间填充后再次设置显示,界面会自动往
- Android(安卓)bitmap 图片缩放,压缩处理
- android改变CheckBox的样式
- Android(安卓)显示系统分析