所以我正在复制类似于facebook聊天气泡的实现,并成功创建了要删除的气泡的drop容器。我希望实现的功能是我应该能够在删除区域中放置一个气泡(恰好是带有十字标记的圆形图像)。当我在圆形图像中拖动气泡时,我希望调整圆形图像的大小并使其变大。因此,当我将气泡留在放大的图像中时,它应该消失。当我将气泡悬停在它上面时,我无法调整此图像的大小。删除功能到位。
我想指点圆形下降区图像的动态重新调整(基于悬停或不悬停的扩展和收缩)
欢迎提出任何指示。提前谢谢。
以下图片供您理解。
答案 0 :(得分:0)
只需修改可用的拖放示例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" />
答案 1 :(得分:-1)
你能检测到悬停事件吗? 请试试这个。
onHover选项
versionNameTextView.setScaleX(1f);
versionNameTextView.setScaleY(1f);
circlerImageView.animate().scaleX(1.5f).scaleY(1.5f).setDuration(500).start();
onHoverEnd
versionNameTextView.setScaleX(1.5f);
versionNameTextView.setScaleY(1.5f);
circlerImageView.animate().scaleX(1f).scaleY(1f).setDuration(500).start();