简单照片浏览器
package com.example.photobrowser;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.ImageView.ScaleType;
import android.widget.LinearLayout;
import android.os.Build;
public class MainActivity extends ActionBarActivity {
private static final ScaleType CENTER_CROP = null;
int []images=new int[]
{R.drawable.a,
R.drawable.b,
R.drawable.d,
R.drawable.e,
R.drawable.f
};
int currentImg=0;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
//隐藏Action Bar
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.activity_main);
//隐藏状态栏
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
LinearLayout main = (LinearLayout) findViewById(R.id.root);
final ImageView image =new ImageView(this);
main.addView(image);
image.setImageResource(images[0]);
image.setScaleType(ScaleType.CENTER_CROP );
image.setOnClickListener(new OnClickListener()
{
@Override
public void onClick(View v)
{
// 改变ImageView里显示的图片
image.setImageResource(images[++currentImg % images.length]);
}
});
}
class MyView extends View{
private Bitmap bitMap;
private Matrix matrix;
public MyView(Context context) {
super(context);
matrix = new Matrix();
matrix.setScale(100f/bitMap.getWidth(), 100f/bitMap.getHeight());
matrix.postTranslate(150, 150);
matrix.postSkew(0.2f,0.2f,150,150);//拉伸
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
canvas.drawBitmap(bitMap, matrix, null);
}
}
}