我已经编写了这个代码,用于从网址加载多个图像并在图像上滑动效果.....但是现在我需要放大&在手指传播的图像...我认为捏缩放...我无法实现缩放功能..也困惑在哪里放置功能或我应该为这个..请帮助....谢谢和问候..
这是我的代码:
package com.conn;
import android.R;
import android.app.Activity;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.ViewFlipper;
public class swipe_touch extends Activity {
private static final String LOGID = "CHECKTHISOUT";
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
private Animation slideLeftIn;
private Animation slideLeftOut;
private Animation slideRightIn;
private Animation slideRightOut;
private ViewFlipper viewFlipper;
int i;
ImageView[] img = new ImageView[24];
String message = "Initial Message";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
//Set up viewflipper
try
{
viewFlipper = new ViewFlipper(this);
for(i=1;i<=3;i++)
{
Log.i("for","loop");
j_comm_func funs = new j_comm_func();
BitmapFactory.Options bmOptions;
bmOptions = new BitmapFactory.Options();
bmOptions.inSampleSize = 1;
Bitmap bm = funs.LoadImage("http://65.175.77.34/newsnow/2462011/largest3/2462011-md-hr-"+i+".jpg", bmOptions);
img[i] = new ImageView(this);
img[i].setImageBitmap(bm);
viewFlipper.addView(img[i]);
}
}
catch(Exception e)
{
Log.i("error",e.getMessage());
}
//set up animations
slideLeftIn = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
slideLeftOut = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
slideRightIn = AnimationUtils.loadAnimation(this, R.anim.slide_in_left);
slideRightOut = AnimationUtils.loadAnimation(this, R.anim.slide_out_right);
//put up a brownie as a starter
setContentView(viewFlipper);
gestureDetector = new GestureDetector(new MyGestureDetector());
}
public class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.v(LOGID,"right to left swipe detected");
viewFlipper.setInAnimation(slideLeftIn);
viewFlipper.setOutAnimation(slideLeftOut);
viewFlipper.showNext();
setContentView(viewFlipper);
} // left to right swipe
else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
Log.v(LOGID,"left to right swipe detected");
viewFlipper.setInAnimation(slideRightIn);
viewFlipper.setOutAnimation(slideRightOut);
viewFlipper.showPrevious();
setContentView(viewFlipper);
}
} catch (Exception e) {
// nothing
}
return false;
}
}
// This doesn't work
@Override
public boolean onTouchEvent(MotionEvent event) {
if (gestureDetector.onTouchEvent(event)){
Log.v(LOGID,"screen touched");
return true;
}
else{
return false;
}
}
}
答案 0 :(得分:0)
将图像加载到WebView中,该视图具有内置的缩放功能。