1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
| public class Zoom extends View
{
private Drawable image;
private int zoomControler=300;
public Zoom(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
image=context.getResources().getDrawable(R.drawable.photo002);
}
public Zoom(Context context, AttributeSet attrs)
{
super(context, attrs);
image=context.getResources().getDrawable(R.drawable.photo002);
}
public Zoom(Context context)
{
super(context);
image=context.getResources().getDrawable(R.drawable.photo002);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
//here u can control the width and height of the images........ this line is very important
image.setBounds((getWidth()/2)-zoomControler, (getHeight()/2-zoomControler), (getWidth()/2)+zoomControler, (getHeight()/2)+zoomControler);
image.draw(canvas);
}
public int getZoom()
{
return zoomControler;
}
public void setZoom(int v)
{
zoomControler+=v;
invalidate();
}
} |
Partager