package com.example.postrotate;
import android.os.*;
import android.app.*;
import android.graphics.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
public class MainActivity extends Activity {
ImageView iv;
Bitmap bmp;
Matrix m;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout ll = new LinearLayout(this);
ll.setOrientation(LinearLayout.VERTICAL);
ll.setGravity(Gravity.CENTER);
setContentView(ll);
iv = new ImageView(this);
bmp = BitmapFactory.decodeResource(getResources(), R.drawable.images);
iv.setImageBitmap(bmp);
ll.addView(iv);
m = new Matrix();
iv.setOnClickListener(new clickListener());
}
class clickListener implements OnClickListener{
public void onClick(View v){
m.postRotate(90);
Bitmap tmp = Bitmap.createBitmap(bmp, 0, 0, bmp.getWidth(), bmp.getHeight(), m, true);
iv.setImageBitmap(tmp);
}
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
留言列表