Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6913653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:14:45+00:00 2026-05-27T09:14:45+00:00

In my problem I am moving an image button onTouch event and the place

  • 0

In my problem I am moving an image button onTouch event and the place where dragging stops redraw an image button at that place. Actually this is working perfectly for simple button but not with image button.

public class NActivity extends Activity implements OnTouchListener {

    private final static int START_DRAGGING = 0;
    private final static int STOP_DRAGGING = 1;

    private ImageButton btn;
    private FrameLayout layout;
    private int status;
    private LayoutParams params;
    private ImageView image;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        layout = (FrameLayout) findViewById(R.id.LinearLayout01);
        // layout.setOnTouchListener(this);

        btn = (ImageButton) findViewById(R.id.imageButton1);
        btn.setDrawingCacheEnabled(true);
        btn.setOnTouchListener(this);

        params = new LayoutParams(LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT);

    }

    public boolean onTouch(View view, MotionEvent me) {
        if (me.getAction() == MotionEvent.ACTION_DOWN) {
            status = START_DRAGGING;
            image = new ImageView(this);
            image.setImageBitmap(btn.getDrawingCache());
            layout.addView(image, params);
        }
        if (me.getAction() == MotionEvent.ACTION_UP) {
            status = STOP_DRAGGING;
            Log.i("Drag", "Stopped Dragging");
        } else if (me.getAction() == MotionEvent.ACTION_MOVE) {
            if (status == START_DRAGGING) {
                System.out.println("Dragging");
                image.setPadding((int) me.getRawX(), (int) me.getRawY(), 0, 0);
                image.invalidate();
            }
        }
        return false;
    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T09:14:45+00:00Added an answer on May 27, 2026 at 9:14 am

    In my example I have used a layout and put and ImageButton inside it, so that image button will inherit the properties of the layout it is inside
    xml:

    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:gravity="center" >
    
        <LinearLayout
            android:id="@+id/ll"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content" >
    
            <ImageButton
                android:src="@drawable/ic_launcher"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="Testing" />
        </LinearLayout>
    
    </FrameLayout>
    

    java:

    public class SomeClass extends Activity implements OnTouchListener {
    
        private LinearLayout ll1;
        private FrameLayout layout;
    
        private float xAxis = 0;
        private float yAxis = 0;
    
        private LinearLayout newLinearLayout;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);
    
            layout = (FrameLayout) findViewById(R.id.LinearLayout01);
    
            ll1 = (LinearLayout) findViewById(R.id.ll);
            newLinearLayout = ll1;
    
            ll1.setOnTouchListener(this);
        }
    
        public void redraw() {
            layout.removeAllViews();
    
            newLinearLayout.setPadding((int) xAxis, (int) yAxis, 0, 0);
    
            layout.addView(newLinearLayout);
    
        }
    
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_MOVE:
                xAxis = event.getX();
                yAxis = event.getY();
                redraw();
    
            case MotionEvent.ACTION_UP:
                System.out.println("intermediate finished");
    
            }
            return true;
        }
    }
    

    It is very simple and easy and in the end it does not matter which component is inside of the LinearLayout because this component does not matter

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to absolute position an image that I will be moving around in
I use this jQuery slide show http://css-tricks.com/moving-boxes/ in my page but the problem in
My Problem is I am Moving the Image onTouchEvent of ImageView, I Have Two
I have an app with multiple animations that are simple, just an image moving
I have a problem moving a Word template from Word 2003 to Word 2007
I am having a problem moving a treenode in a treeview to a listbox.
We have a common problem of moving our development SQL 2005 database onto shared
I'm moving my ASP.NET website to a new provider. Only problem is, old host
Problem: I have two spreadsheets that each serve different purposes but contain one particular
Problem (simplified to make things clearer): 1. there is one statically-linked static.lib that has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.