求解 android 图片点击一下就放大到全屏,再点一下就回到原界面,这个android源码谁有呢?
发布网友
发布时间:2022-05-20 18:13
我来回答
共3个回答
热心网友
时间:2023-11-08 01:07
package com.pic;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Matrix;
import android.os.Bundle;
import android.view.Display;
import android.view.KeyEvent;
import android.view.MotionEvent;
import android.widget.ImageView;
public class TestanroidpicActivity extends Activity {
/** Called when the activity is first created. */
Bitmap bp=null;
ImageView imageview;
float scaleWidth;
float scaleHeight;
int h;
boolean num=false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Display display=getWindowManager().getDefaultDisplay();
imageview=(ImageView)findViewById(R.id.imageview);
bp=BitmapFactory.decodeResource(getResources(),R.drawable.icon);
int width=bp.getWidth();
int height=bp.getHeight();
int w=display.getWidth();
int h=display.getHeight();
scaleWidth=((float)w)/width;
scaleHeight=((float)h)/height;
imageview.setImageBitmap(bp);
}
@Override
public boolean onTouchEvent(MotionEvent event) {
switch(event.getAction()){
case MotionEvent.ACTION_DOWN:
if(num==true) {
Matrix matrix=new Matrix();
matrix.postScale(scaleWidth,scaleHeight);
Bitmap newBitmap=Bitmap.createBitmap(bp, 0, 0, bp.getWidth(), bp.getHeight(), matrix, true);
imageview.setImageBitmap(newBitmap);
num=false;
}
else{
Matrix matrix=new Matrix();
matrix.postScale(1.0f,1.0f);
Bitmap newBitmap=Bitmap.createBitmap(bp, 0, 0, bp.getWidth(), bp.getHeight(), matrix, true);
imageview.setImageBitmap(newBitmap);
num=true;
}
break;
}
return super.onTouchEvent(event);
}
}
热心网友
时间:2023-11-08 01:08
android官网有啊
热心网友
时间:2023-11-08 01:08
用ImageView 然后放大,监听touch事件,读出屏幕的分辨率尺寸,然后将读出的尺寸通过参数传到放大的方法中, 然后再监听到touch后,还原就可以了。你查下ImageView或者Drawable的放大缩小方法,看看哪个方法的参数有要传上下左右边界的。网上好多这样的例子