安卓简单的图片浏览器。
<?xml version=”1.0″ encoding=”utf-8″?>
<LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”fill_parent”
android:layout_height=”fill_parent”
android:orientation=”vertical”
android:id=”@+id/root”>
</LinearLayout>
package com.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.LinearLayout;
public class TestActivity extends Activity {
int [] images=new int[]{R.drawable.a,
R.drawable.b,R.drawable.c,
R.drawable.d,R.drawable.b
};
int currentImg=0;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout main=(LinearLayout) findViewById(R.id.root);
final ImageView image =new ImageView(this);
main.addView(image);
image.setImageResource(images[0]);
image.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(currentImg>=4){
currentImg=-1;
}
image.setImageResource(images[++currentImg]);
}
});
}
}