`
isiqi
  • 浏览: 16702094 次
  • 性别: Icon_minigender_1
  • 来自: 济南
社区版块
存档分类
最新评论

2010.06.05日志:Android Gallery左右循环旋转方法

阅读更多

如图:

2

先在attr.xml里写个Gallery的样式

1:  <?xml version="1.0" encoding="utf-8"?>
2:  <resources>
3:      <declare-styleable name="Gallery">
4:          <attr name="android:galleryItemBackground" />
5:      </declare-styleable>
6:      <!-- 定义Layout外部resources 的xml文件,用来改变Layout的背景图 -->
7:  </resources>
8:  

然后在mainActivity里的OnCreate里:

1:  setContentView(R.layout.main);
2:  
3:          imageAdapter = new myImageAdapter(this);
4:  
5:          gallery = (Gallery) findViewById(R.id.Gallery_preView);
6:          imageView = (ImageView) findViewById(R.id.ImageView_photo);
7:  
8:          gallery.setAdapter(imageAdapter);
9:          gallery.setSelection(200);//设置Gallery的起始位置

下面是imageAdapter的类,它继承BaseAdapter

图片资源:

1:  protected int[] myImageIds = { R.drawable.vista_1, R.drawable.vista_2,
2:              R.drawable.vista_3, R.drawable.vista_4, R.drawable.vista_5,
3:              R.drawable.vista_6, };

构造里:

 1:  public myImageAdapter(Context context) {
 2:          mContext = context;
 3:          /* 使用res/values/attr.xml中的<declare-styleable>定义的Gallery属性 */
 4:          TypedArray typed_array = context
 5:                  .obtainStyledAttributes(R.styleable.Gallery);
 6:          mGalleryItemBackground = typed_array.getResourceId(
 7:                  R.styleable.Gallery_android_galleryItemBackground, 0);
 8:          /* 让对象的styleable 属性能够反复使用 */
 9:          typed_array.recycle();
10:      }
11:  

getCount()方法:

1:  @Override
2:      public int getCount() {
3:          // TODO Auto-generated method stub
4:          // return myImageIds.length;
5:          return Integer.MAX_VALUE;
6:      }

getView()方法:

 1:  @Override
 2:      public View getView(int position, View convertView, ViewGroup parent) {
 3:          ImageView i = new ImageView(mContext);
 4:          
 5:          if (position < 0) {
 6:              position = position + myImageIds.length;
 7:          }
 8:          i.setImageResource(myImageIds[position % myImageIds.length]);
 9:          i.setScaleType(ImageView.ScaleType.FIT_XY);
10:          i.setLayoutParams(new Gallery.LayoutParams(128, 128));
11:          i.setBackgroundResource(mGalleryItemBackground);
12:          return i;
13:      }
分享到:
评论

相关推荐

    android-4.1.1.4-API文档-中文版.zip

    赠送jar包:android-4.1.1.4.jar; 赠送原API文档:android-4.1.1.4-javadoc.jar; 赠送源代码:android-4.1.1.4-sources.jar; 赠送Maven依赖信息文件:android-4.1.1.4.pom; 包含翻译后的API文档:android-4.1....

    JMeterPlugins.jar

    JMeter导入jmx运行脚本时出现这样的错误jmeter.save.SaveService: Conversion error com.thoughtworks.xstream.converters.ConversionException:2016/12/20 13:51:55 ERROR - jmeter.save.SaveService: Conversion ...

    Android串口(AndroidSerialPort)通信代码,快速学会串口通信的demo。注释超全

    在Android平台上进行串口通信是开发物联网应用或者与硬件设备交互时常见的需求。本文将详细介绍如何使用AndroidSerialPort库来实现这一功能,并提供一个详细注释的代码示例,帮助开发者快速掌握Android串口通信的...

    fastjson-1.1.70.android.jar

    fastjson-1.1.70.android.jar,安卓专用fastjson解析jar包

    程序员表白程序 源码开放性 第一辑 不断更新(程序之爱系列第一辑)

    【程序员表白程序 源码开放性 第一辑 不断更新(程序之爱系列第一辑)】 这个项目是一个程序员为了表达爱意而创作的独特程序,它不仅展现了编程技术的运用,还融合了情感的传递。程序员们常常以其独特的思维方式和...

    Android N 7.0中报错:android.os.FileUriExposedException的解决方法

    安装Apk时报错:android.os.FileUriExposedException: file:///storage/emulated/0/Download/appName-2.3.0.apk exposed beyond app through Intent.getData(),通过查找相关的资料终于找到了解决的方法,下面分享给...

    Android 使用Matrix.postRotate方法旋转图片.rar

    Android图像操作一例,使用Matrix.postRotate方法旋转图片,这些的图片格式是BMP,其它格式可能也能用吧,没测试,旋转BMP图片的效果如截图所示,用户单击向左或向右按钮后,图片旋转90度,旋转角度根据自己需要...

    iperf_android.apk.zip

    在本文中,我们将深入探讨iPerf的基本功能、工作原理、使用方法,特别是针对Android系统的iperf3版本。 一、iPerf概述 iPerf最初是由Steve Lewis在2000年开发的,主要服务于Linux系统。随着时间的推移,它已经发展...

    ARM.CMSIS.4.5.0

    **CMSIS(Cortex Microcontroller Software Interface Standard)是ARM公司为基于Cortex-M系列处理器的微控制器设计的一套软件接口标准。它旨在提供一个统一的软件接口,使得开发者在不同的微控制器之间进行移植时...

    Android Studio Dolphin (android-studio-2021.3.1.4-mac.part2)

    Android Studio Dolphin (2021.3.1) Canary 4 (android-studio-2021.3.1.4-mac.zip)海豚 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起下载两个压缩包进行解压使用: Android Studio Dolphin ...

    Android Studio Chipmunk (android-studio-2021.2.1.10-mac.part1)

    Android Studio Chipmunk (2021.2.1) Beta 3 (android-studio-2021.2.1.10-mac.zip)花栗鼠 适用于macOS Intel芯片系统,文件分割成两个压缩包,必须一起解压使用: Android Studio Chipmunk (android-studio-2021...

    Android Studio Bumblebee (android-studio-2021.1.1.22-windows)

    studio-2021.1.1.22-windows.exe)大黄蜂,适用于Windows x86_64系统,是Android Studio 4.3(Android Studio Arctic Fox 2020.3.1.26新版本命名)版本之后的新版本Android Studio Bumblebee 可以理解为:Android ...

    Android FastJSON小示例

    在Android开发中,数据交换和序列化是常见的需求,FastJSON是阿里巴巴提供的一款高效、功能丰富的JSON库,它被广泛应用于Android Studio项目中。本文将详细介绍如何在Android Studio中使用FastJSON进行JSON解析和...

    com.google.zxing两个jar包

    使用ZXing-JavaSE.jar时,开发者需要将其添加到项目依赖中,然后通过调用相应的类和方法来实现条码的生成和解码。例如,要解码一个图像中的条码,可以创建`BufferedImage`对象,然后使用`BinaryBitmap`和`...

    AXMLPrinter2.S.jar

    AXMLPrinter2.S.jar 把反编译出来的layout布局文件解析成正常代码

    Androidlua.so, lua4java.jar

    在Android平台上,开发者有时会利用Lua这种轻量级的脚本语言来辅助开发,以提高应用的灵活性和性能。在给定的文件信息中,“Androidlua.so”和“lua4java.jar”是两个关键组件,它们是将Lua集成到Android应用中的...

    android.jar源码

    在Android应用开发中,`android.jar`是一个至关重要的组件,它是Android SDK的核心库文件,包含了Android系统框架API的所有公开类和方法。开发者通过这个库与Android操作系统进行交互,实现各种功能。本文将深度探讨...

    Android support.v7包

    Android support.v7包

    gcc 4.4.7-4.el6.x86_64安装包

    8. `cloog-ppl-0.15.7-1.2.el6.x86_64.rpm`:Cloog是基于格的调度器(GSS)的接口,用于自动代码生成,尤其是循环优化,配合PPL一起工作。 安装这些RPM包,你可以获得完整的GCC 4.4.7编译环境,不仅能够编译C和C++...

    javax.naming.NamingException: Cannot create resource instance

    javax.naming.NamingException: Cannot create resource instance类加载异常,希望可以帮助跟我一样错误的人。

Global site tag (gtag.js) - Google Analytics