Try the below codeStore ur image in drawable and give
that name for R.drawable._
import android.app.Activity;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.os.Bundle;
import android.view.Display;
import android.view.GestureDetector;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.GestureDetector.OnGestureListener;
import android.widget.Toast;
public class ScrollPic extends Activity implements OnGestureListener
{
// private static final int X_MAX = 800;
//private static final int Y_MAX = 600;
private int scrollX = 0;
private int scrollY = 0;
int scrollRate = 20;
//window size
int picWidth;
int picHeight;
int winWidth;
int winHeight;
int maxWidth;
int maxHeight;
int pixel;
public Float xtouch;
public Float ytouch;
MyView main;
Bitmap bmp;
Display d;
Bitmap adapt;
Resources res;
Paint paint;
GestureDetector gestureScanner;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
WindowManager w = getWindowManager();
d = w.getDefaultDisplay();
gestureScanner = new GestureDetector(this);
paint = new Paint();
res = getResources();
bmp = BitmapFactory.decodeResource(res, R.drawable.map1);
adapt = Bitmap.createBitmap(bmp);
picWidth = bmp.getWidth();
picHeight = bmp.getHeight();
winWidth = d.getWidth();
winHeight = d.getHeight();
main = new MyView(this);
maxWidth = Math.min(picWidth, d.getWidth());
maxHeight = Math.min(picHeight,d.getHeight());
setContentView(main,new
ViewGroup.LayoutParams(picWidth,picHeight));
}
/* public boolean dispatchTouchEvent(MotionEvent event){
}*/
@Override
public boolean onTouchEvent(MotionEvent me)
{
return gestureScanner.onTouchEvent(me);
}
public boolean onScroll(MotionEvent e1, MotionEvent e2, float
distanceX, float distanceY)
{
main.handleScroll(distanceX,distanceY);
return true;
}
///
//
public boolean onDown(MotionEvent e)
{
return true;
}
public boolean onFling(MotionEvent e1, MotionEvent e2, float
velocityX, float velocityY)
{
return true;
}
public void onLongPress(MotionEvent e)
{
String s= "picW="+ picWidth +" picH="+ picHeight+"
winW="+d.getWidth()+" winH="+d.getHeight();
//Toast.makeText(ScrollPic.this,s,Toast.LENGTH_LONG).show();
xtouch = e.getX();
ytouch = e.getY();
System.out.println("Clicked on ("+xtouch+","+ytouch+")");
String str = "Clicked on ("+xtouch+","+ytouch+")";
Toast.makeText(ScrollPic.this,str,Toast.LENGTH_LONG).show();
}
public void onShowPress(MotionEvent e)
{
}
public boolean onSingleTapUp(MotionEvent e)
{
return true;
}
class MyView extends View
{
public MyView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
canvas.drawBitmap(adapt, 0, 0, paint);
}
public void handleScroll(float distX, float distY)
{
// X-Axis
if(distX > 6.0)
{
if(scrollX < picWidth-winWidth)
{
scrollX += scrollRate;
}
}
else if(distX < -6.0)
{
if(scrollX >= scrollRate)
{
scrollX -= scrollRate;
}
}
if(distY > 6.0)
{
if(scrollY < picHeight-winHeight)
{
scrollY += scrollRate;
}
else
{
scrollY = picHeight-winHeight;
}
}
else if(distY < -6.0)
{
if(scrollY >= scrollRate)
{
scrollY -= scrollRate;
}
}
if((scrollX <= picWidth-winWidth) && (scrollY <= picHeight-
winHeight))
{
System.out.println("DRAWINGGG");
System.out.println(scrollX+" "+scrollY +" "+
bmp.getWidth()+" "+adapt.getWidth());
adapt = Bitmap.createBitmap(bmp, scrollX,
scrollY,winWidth,winHeight);//
invalidate();
}
}
}
}
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from