Android Drag and drop images on the Screen?

后端 未结 5 1492
太阳男子
太阳男子 2020-11-27 19:36

I m working on project user to move the image in one position to Another position on the screen. I have written a sample code to move the image but the problem here is if I

5条回答
  •  时光取名叫无心
    2020-11-27 20:04

    Actually you can avoid this problem by declaring the images programmatically .

    int id = getResources().getIdentifier("image1", "drawable", getPackageName());
    ImageView imageView1 = new ImageView(this);
    LinearLayout.LayoutParams vp = 
    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT);
    imageView1.setLayoutParams(vp);        
    imageView1.setImageResource(id);        
    someLinearLayout.addView(imageView1); 
    
     int id = getResources().getIdentifier("image2", "drawable", getPackageName());
    ImageView imageView2 = new ImageView(this);
    LinearLayout.LayoutParams vp1 = 
    new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, 
                    LayoutParams.WRAP_CONTENT);
    imageView2.setLayoutParams(vp1);        
    imageView2.setImageResource(id);        
    someLinearLayout.addView(imageView2); 
    

    and add touch events to the added imageviews

提交回复
热议问题