I am writing SMIL composer for the class, and I planned to make the ink support upholstery and drop so that you can place the images and text as you want. I looked through the examples and made some of my own, but when I go to implement drag and drop in my project, this will not work. Here is the main code that matters:
public class ComposerActivity extends Activity { @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()){
Here is the .xml composer:
... <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 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 to magnification, from 40x40 to 60x60, as it should. But he does not follow my finger across the screen, and that’s where I got stuck.
Any input is welcome.
Corry
source share