最近在项目中用到图片轮播,试了Gallery,ViewFlipper,ViewPager,感觉Gallery最符合需求,但是Gallery的系统边框很难看,项目中要求用自己的背景图片。

下面来看一下使用Gallery实现图片轮播

运行效果:


布局文件:

[java] view plain copy
  1. <FrameLayout
  2. >
  3. />
  4. >
  5. />
  6. />
  7. />
  8. </FrameLayout>

其中,android:fadingEdge="none"消除图片两边的阴影。使用FrameLayout在底部显示小圆点

[java] view plain copy
  1. publicclassextends private privateint;
  2. private
  3. privatestaticfinalint;
  4. publicvoid super ].setImageDrawable(getBaseContext().getResources()
  5. newthis new ,);
  6. privatevoid new privatenew
  7. publicvoid new ;
  8. *开一个线程执行耗时操作
  9. */ privatenew
  10. publicvoid super switch case:
  11. break default break *设置小圆点显示,position会一直增加,如果要循环显示图片,需要对position取余,否则数组越界
  12. */ privatenew
  13. publicvoid intlong int if){
  14. ].setImageDrawable(getBaseContext()
  15. if)){
  16. ].setImageDrawable(getBaseContext()
  17. if){
  18. ]
  19. publicvoid
  20. *点击事件,点击图片进入SecondActivity
  21. */ privatenew
  22. publicvoidint long new thisclass }

ImageAdapter类,重写android.widget.BaseAdapter,用于描述图像信息。

[java] view plain copy
  1. publicclassextends private privateint privatestaticfinalint;
  2. public this
  3. publicint return
  4. publicint return
  5. publiclongint return
  6. publicint new new new ,,,);
  7. return }


如果用系统背景,可以这样写

[java] view plain copy
  1. int private public //获得Gallery组件的属性 );
  2. }

在getview中设置

[java] view plain copy
  1. imageView.setBackgroundResource(mGalleryItemBackground);

Gallery组件属性信息定义在res\values\attrs.xml

[java] view plain copy
  1. <?xmlversion=encoding=?>
  2. >
  3. />
  4. </resources>

更多相关文章

  1. Android保存图片到相册
  2. Android(安卓)InputMethod 源码分析,显示输入法流程
  3. Android下载的视频,在相册中显示
  4. 修改checkbox框颜色
  5. Building Custom Components/建立自定义组件
  6. 小记 ScrollView 隐藏 里面空间填充后再次设置显示,界面会自动往
  7. Android(安卓)bitmap 图片缩放,压缩处理
  8. android改变CheckBox的样式
  9. Android(安卓)显示系统分析

随机推荐

  1. android进行录音功能并保存播放
  2. Android(安卓)Framework 修改设备连接电
  3. Android(安卓)SVG 兼容低版本API
  4. Android(安卓)layout系列-autolayout
  5. Android(安卓)常用RGB值以及中英文名称
  6. Android菜鸟笔记-实现自动连接到指定的Wi
  7. android配置cmake
  8. eclipse下 Failed to find an AVD compat
  9. Android学习心得(24) --- Android(安卓)Han
  10. php7中停止php-fpm服务的方法详解