Note that there are some explanatory texts on larger screens.

plurals
  1. POAndroid: Drag and Drop issue
    primarykey
    data
    text
    <p>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:</p> <pre><code>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 } </code></pre> <p>Here is the composer.xml:</p> <pre><code>... &lt;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"&gt; &lt;/FrameLayout&gt; ... </code></pre> <p>and the image_add.xml:</p> <pre><code>&lt;View android:id="@+id/image" android:layout_gravity="top" xmlns:android="http://schemas.android.com/apk/res/android"/&gt; </code></pre> <p>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 40x40 to 60x60 like it should. But it doesn't follow my finger across the screen, and thats where I'm stuck.</p> <p>Any input is appreciated. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload