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

Apps how to draw a view in click position

Discussion in 'Android Development' started by desatir7316, Jan 6, 2015.

  1. desatir7316

    desatir7316 Member
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    35
    Joined:
    Dec 25, 2014

    Dec 25, 2014
    35
    2
    16
    Male
    hi there
    i want to show a view in a position that user click
    how to do it?
    here is my code:

    Code (Text):
    1.    
    2. public boolean onTouchEvent(MotionEvent event) {
    3.         // TODO Auto-generated method stub
    4.          super.onTouchEvent(event);
    5.        
    6.          ImageView iv = new ImageView(this);
    7.          iv.setVisibility(View.VISIBLE);
    8.          iv.setImageResource(R.drawable.glass);    
    9.          ((RelativeLayout) findViewById(R.id.container)).addView(iv);
    10.  
    11.          return true;
    12.     }
    13.  
    thanks a lot
     

    Advertisement

    #1 desatir7316, Jan 6, 2015
    Last edited: Jan 6, 2015
  2. mango_89

    mango_89 Lurker
    Rank:
    None
    Points:
    5
    Posts:
    3
    Joined:
    Jan 4, 2015

    Jan 4, 2015
    3
    0
    5
    Male
    Hi,
    I am not sure if this will help you. I am considering on this way.
    Put RelativeLayout as main layout. Then you should get coordinates of user's click and when you will have this just add view on the RelativeLayout regarding of coordinates.

    Hope that I've directed you on right way

    best regards.
     
  3. desatir7316

    desatir7316 Member
    Thread Starter
    Rank:
    None
    Points:
    16
    Posts:
    35
    Joined:
    Dec 25, 2014

    Dec 25, 2014
    35
    2
    16
    Male
    hi mango
    thanks for your help
    my problem solved, im so sorry to forget update this post
    at this time i dont have my codes to update the result

    thanks agaiin
     

Share This Page

Loading...