Simple Picture Viewer

单击图片会移动的例子
Logical source:

package org.crazyit.mixview;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MixViewActivity extends Activity {
    /** Called when the activity is first created. */
	int [] images = new int[]{
	R.drawable.tu1,
	R.drawable.tu2,
	R.drawable.tu3,
	};
	
	int currentImg = 0;
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        LinearLayout layout = (LinearLayout)findViewById(R.id.mix_layout);
        
        
        final ImageView image = new ImageView(this);
        
        
        layout.addView(image);
        
        image.setImageResource(images[0]);
        image.setVerticalFadingEdgeEnabled(true);

        image.setOnClickListener(new OnClickListener(){
			public void onClick(View v) {				
				if(currentImg >= 2){
					currentImg = -1;
				}
				image.setImageResource(images[++currentImg]);
				image.setVerticalFadingEdgeEnabled(true);
			}    	
        });
        
    }
}

Graphic user interface xml:





    





你可能感兴趣的:(Android)