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

  • Home
  • SEARCH
  • 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 3986460
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T06:00:55+00:00 2026-05-20T06:00:55+00:00

I’m writing a SMIL composer for a class, and I was planning on making

  • 0

I’m writing a SMIL composer for a class, and I was planning on making the canvas support drap and drop, so you can place pictures and text however you want. I’ve looked through examples and did a few on my own, but when I go to implement the drag and drop in my project, it doesn’t work. Here is the main code that matters:

public class ComposerActivity extends Activity {
    /** Called when the activity is first created. */

    @Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.composer);

    Button add = (Button)findViewById(R.id.addBtn);
    ...

    add.setOnClickListener(mClick);
    ...
}

OnClickListener mClick = new OnClickListener() {
    @Override
    public void onClick(View v){        
        if(v.getId() == R.id.addBtn)
        {
            FrameLayout fl = (FrameLayout)findViewById(R.id.Canvas); 
            LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
            View itemView = inflater.inflate(R.layout.image_add, null);

            View image = (View)itemView.findViewById(R.id.image);   
            image.setBackgroundResource(R.drawable.icon); 

            fl.addView(itemView, new FrameLayout.LayoutParams(40, 40));  

            image.setOnTouchListener(drag);
        }
        ...

OnTouchListener drag = new OnTouchListener(){
    @Override 
    public boolean onTouch(View v, MotionEvent event){ 
        FrameLayout.LayoutParams par = (LayoutParams) v.getLayoutParams(); 
        switch(v.getId()){//What is being touched 
            case R.id.image:{//Which action is being taken 
                switch(event.getAction()){ 
                    case MotionEvent.ACTION_MOVE:{  
                        par.topMargin = (int)event.getRawY() - (v.getHeight()); 
                        par.leftMargin = (int)event.getRawX() - (v.getWidth()/2); 
                        v.setLayoutParams(par); 
                        break; 
                    }//inner case MOVE 
                    case MotionEvent.ACTION_UP:{ 
                        par.height = 40; 
                        par.width = 40; 
                        par.topMargin = (int)event.getRawY() - (v.getHeight()); 
                        par.leftMargin = (int)event.getRawX() - (v.getWidth()/2); 
                        v.setLayoutParams(par); 
                        break; 
                    }//inner case UP 
                    case MotionEvent.ACTION_DOWN:{ 
                        par.height = 60; 
                        par.width = 60; 
                        v.setLayoutParams(par); 
                        break; 
                    }//inner case UP 
                }//inner switch 
                break; 
            }//case image
        }//switch 
            return true; 
        }//onTouch 
    };//drag
}

Here is the composer.xml:

...
<FrameLayout android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/TopBar" 
    android:layout_above="@+id/addBtn" 
    android:id="@+id/Canvas"
    android:layout_gravity="top">

</FrameLayout>
...

and the image_add.xml:

<View android:id="@+id/image" 
        android:layout_gravity="top"
        xmlns:android="http://schemas.android.com/apk/res/android"/> 

When I click the add button on my composer, it successfully adds the image to the canvas, and when I touch the image, it responds by getting bigger, from 40×40 to 60×60 like it should. But it doesn’t follow my finger across the screen, and thats where I’m stuck.

Any input is appreciated.

  • 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-20T06:00:55+00:00Added an answer on May 20, 2026 at 6:00 am

    I studied the Android Launcher code to see how they did drag and drop. I really like their object model. What they did, and it might be good for you to consider, is move the responsibility for handling drag and drop out to the ViewGroup in which all the draggable views are inside of. Touch events get handled there rather than in your views.

    Two of the key classes:

    DragLayer – implements a custom ViewGroup, which coordinates movement of views on the screen. The Launcher DragLayer is a subclass of FrameLayout.

    DragController – This object is the controller that does most of the work to support dragging and dropping.

    The other thing they do is not move the actual view until you drop the object you are dragging. It does not look that way though because on the screen you see a bitmap constructed from the view moving as your finger (or pointer) moves.

    I built a simple example and wrote it up. See http://blahti.wordpress.com/2011/01/17/moving-views-part-2/
    Source code of the example is there too.

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

Sidebar

Related Questions

I am writing an app with both english and french support. The app requests
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am doing a simple coin flipping experiment for class that involves flipping a
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I have a reasonable size flat file database of text documents mostly saved in

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.