SwitcherActivity.java
package com.mobsandgeeks.ise;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.view.WindowManager;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageSwitcher;
import android.widget.ImageView;
import android.widget.ViewSwitcher;
public class SwitcherActivity extends Activity implements ViewSwitcher.ViewFactory, OnItemSelectedListener {
private Gallery gallery;
private ImageSwitcher imageSwitcher;
private ImageAdapter ia;
@Override
public void onCreate(Bundle savedInstanceState) {
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
gallery = (Gallery) findViewById(R.id.gallery);
ia = new ImageAdapter(this);
gallery.setAdapter(ia);
//Event listeners
gallery.setOnItemSelectedListener(this);
}
private class ImageAdapter extends BaseAdapter {
private Context context;
private ImageAdapter(Context context) {
this.context = context;
}
private int[] IMAGE_IDS = {
R.drawable.android, R.drawable.gingerbread, R.drawable.honeycomb,
R.drawable.lg_optimus, R.drawable.nexus_one, R.drawable.nexus_s,
R.drawable.oha
};
public int getCount() {
return IMAGE_IDS.length;
}
public Object getItem(int position) {
return IMAGE_IDS[position];
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView iv = new ImageView(context);
iv.setImageResource(IMAGE_IDS[position]);
iv.setLayoutParams(new Gallery.LayoutParams(840, 400));
return iv;
}
}
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
}
public void onNothingSelected(AdapterView<?> parent) {
}
public View makeView() {
return null;
}
}
main.xml<CODE>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Gallery
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</CODE>Pronto!!!
É só colocar as fotos no na pasta drawable
=D
Vitor Yudi Hansen