1. Download our Official Android App: Forums for Android!

Apps Please Help Me

Discussion in 'Android Development' started by Nits, Sep 26, 2010.

  1. Nits

    Nits Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 26, 2010

    Sep 26, 2010
    2
    0
    5
    Hello,
    This is Nitesh, I m new to Android Programming
    I am writing a program for Image zoom-In-Out on Button Click.
    Please Help me i m getting problems.

    1. If I do Normal display, it do display both image and button but fails to change dimensions.

    2. If I use Canvas to draw Image then i m not getting how to draw or make display button on Canvas.

    these are my problems.
    please Help Me.

    Thanking You
     

    Advertisement

  2. AlbertPucciani

    Rank:
    None
    Points:
    36
    Posts:
    71
    Joined:
    Oct 2, 2010

    Oct 2, 2010
    71
    8
    36
    Computer Programmer
    Hi Nits,

    First, have you figured out how to put a picture, and a button on screen using an Activity and a View?
     
    Nits likes this.
  3. Nits

    Nits Lurker
    Thread Starter
    Rank:
    None
    Points:
    5
    Posts:
    2
    Joined:
    Sep 26, 2010

    Sep 26, 2010
    2
    0
    5
    Hello Thnx for your suggestion

    this is what i found working. foll code work for Zoom In-Out image when we scroll.
    but i want to make the same for button click. & i failed to show button.


    package com.example.zoom;

    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.Canvas;
    import android.graphics.Bitmap.Config;
    import android.graphics.drawable.Drawable;
    import android.graphics.drawable.ShapeDrawable;
    import android.graphics.drawable.shapes.ArcShape;
    import android.view.KeyEvent;
    import android.view.View;
    import android.view.ViewGroup;
    import android.widget.Button;
    import android.widget.RelativeLayout;
    import android.widget.RemoteViews;


    public class Zoom extends View{
    public Drawable image,b;
    private int zoomControler=20;
    public RelativeLayout rl;
    public View canvas,iv;
    ViewGroup vg;
    Button btn;
    Canvas c;
    public Zoom(Context context)
    {
    super(context);


    iv = (Button) findViewById(R.id.Button01);
    image=context.getResources().getDrawable(R.drawable.icon);

    setFocusable(true);
    }

    @Override
    protected void onDraw(Canvas canvas) {
    // TODO Auto-generated method stub
    super.findViewById(R.id.Button01);
    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);


    }
    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event) {

    if(keyCode==KeyEvent.KEYCODE_DPAD_UP)// zoom in
    zoomControler+=10;
    if(keyCode==KeyEvent.KEYCODE_DPAD_DOWN) // zoom out
    zoomControler-=10;
    if(zoomControler<10)
    zoomControler=10;

    invalidate();
    return true;
    }


    }
     

Share This Page

Loading...