因此,我正在使用Facebook聊天气泡复制类似的实现,并成功创建了要删除气泡的放置容器。我要实现的功能是,我应该能够在删除区域(恰好是带有十字标记的圆形图像)中放置气泡。当我将气泡拖动到圆形图像中时,我希望调整圆形图像的大小并将其放大。因此,当我将气泡留在放大的图像中时,它应该消失了。当我将气泡悬停在该图像上时,无法调整该图像的大小。删除功能到位。

我想要有关动态调整圆形拖放区图像大小的指针(基于已悬停或未悬停的展开和收缩)

欢迎任何指针。提前致谢。

以下图片供您理解。

android - 调整下落区的大小以消除气泡-LMLPHP

android - 调整下落区的大小以消除气泡-LMLPHP

最佳答案

只需修改可用的here拖放示例即可实现您的预​​期行为。希望这可以帮助。

public class MyNewActivity extends Activity {
ImageView img;
String msg;
private android.widget.RelativeLayout.LayoutParams layoutParams;
private View target;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.my_drag_drop);
    img=(ImageView)findViewById(R.id.imageView);
    target=findViewById(R.id.target);

    img.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            ClipData.Item item = new ClipData.Item((CharSequence)v.getTag());
            String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};

            ClipData dragData = new ClipData(v.getTag().toString(),mimeTypes, item);
            View.DragShadowBuilder myShadow = new View.DragShadowBuilder(img);

            v.startDrag(dragData,myShadow,null,0);
            return true;
        }
    });

    img.setOnDragListener(onDragListener1);
    target.setOnDragListener(onDragListener1);

    img.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (event.getAction() == MotionEvent.ACTION_DOWN) {
                ClipData data = ClipData.newPlainText("", "");
                View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(img);

                img.startDrag(data, shadowBuilder, img, 0);
                img.setVisibility(View.INVISIBLE);
                return true;
            }
            else
            {
                return false;
            }
        }
    });
}

private boolean isViewScalled=false;

View.OnDragListener onDragListener1=new View.OnDragListener() {
    @Override
    public boolean onDrag(View v, DragEvent event) {
        switch(event.getAction())
        {
            case DragEvent.ACTION_DRAG_STARTED:
                Log.d(msg, "Action is DragEvent.ACTION_DRAG_STARTED");

                // Do nothing
                break;

            case DragEvent.ACTION_DRAG_ENTERED:
                Log.d(msg, "Action is DragEvent.ACTION_DRAG_ENTERED");
                if(!isViewScalled) {
                    target.animate().scaleXBy(.5f).scaleYBy(.5f).start();
                    isViewScalled=true;
                }
                break;

            case DragEvent.ACTION_DRAG_EXITED :
                Log.d(msg, "Action is DragEvent.ACTION_DRAG_EXITED");
                if(isViewScalled) {
                    target.animate().scaleXBy(-.5f).scaleYBy(-.5f).start();
                    isViewScalled=false;
                }
                break;

            case DragEvent.ACTION_DRAG_LOCATION  :
                Log.d(msg, "Action is DragEvent.ACTION_DRAG_LOCATION");
                break;

            case DragEvent.ACTION_DRAG_ENDED   :
                Log.d(msg, "Action is DragEvent.ACTION_DRAG_ENDED");

                // Do something
                break;

            case DragEvent.ACTION_DROP:
                Log.d(msg, "ACTION_DROP event");
                break;
            default: break;
        }
        return true;
    }
};

}

和布局
<?xml version="1.0" encoding="utf-8"?>
<ImageView
    android:layout_width="75dp"
    android:layout_height="75dp"
    android:id="@+id/imageView" android:scaleType="fitXY"
    android:src="@drawable/abc_btn_radio_material" />


<ImageView
    android:layout_width="125dp"
    android:layout_height="125dp"  android:scaleType="fitXY"
    android:id="@+id/target" android:layout_centerHorizontal="true"
    android:src="@drawable/abc_btn_radio_material" android:layout_alignParentBottom="true" />

关于android - 调整下落区的大小以消除气泡,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/34355980/

10-13 00:34