WEB开发网
开发学院手机开发Android 开发 Android gallery实现图片的左右循环旋转源码分享 阅读

Android gallery实现图片的左右循环旋转源码分享

 2010-11-05 00:55:36 来源:WEB开发网   
核心提示:import android.widget.Toast;import android.widget.AdapterView.OnItemSelectedListener;public class EX03_15 extends Activity{private TextView mTextView01;@Overrid

import android.widget.Toast;

import android.widget.AdapterView.OnItemSelectedListener;

public class EX03_15 extends Activity

{

private TextView mTextView01;

@Override

public void onCreate(Bundle savedInstanceState)

{

super.onCreate(savedInstanceState);

setContentView(R.layout.main);

Gallery gallery = ((Gallery) findViewById(R.id.myGallery1));

gallery.setAdapter(new ImageAdapter(this));

gallery.setSelection(200);

gallery.setOnItemSelectedListener(new OnItemSelectedListener()

{

public void onItemSelected(AdapterView arg0, View arg1, int arg2,

long arg3)

{

Toast.makeText(EX03_15.this, "当前位置:" + arg2, Toast.LENGTH_SHORT).show();

}

public void onNothingSelected(AdapterView arg0)

{

}

});

}

public class ImageAdapter extends BaseAdapter

{

/* 类成员 myContext为Context父类 */

private Context myContext;

/*声明GalleryItemBackground*/

int mGalleryItemBackground;

/* 使用android.R.drawable里的图片作为图库来源,类型为整数数组 */

private int[] myImageIds =

{ R.drawable.a1, R.drawable.a2, R.drawable.a3, R.drawable.a4,

R.drawable.a5, R.drawable.a27 };

/* 构造器只有一个参数,即要存储的Context */

public ImageAdapter(Context c)

{

myContext = c;

/*

* 使用在res/values/attrs.xml中的定义 的Gallery属性.

*/

TypedArray a = obtainStyledAttributes(R.styleable.Gallery);

/* 取得Gallery属性的Index id */

mGalleryItemBackground = a.getResourceId(

R.styleable.Gallery_android_galleryItemBackground, 0);

/* 让对象的styleable属性能够反复使用 */

a.recycle();

Tags:Android gallery 实现

编辑录入:coldstar [复制链接] [打 印]
赞助商链接