ViewRootImpl:在三星Galaxy S6上报告下降结果:false



我正在开发一款包含拖放功能的游戏。它适用于除三星Galaxy S6以外的所有设备。

class MyDragListener implements View.OnDragListener {
Drawable normalShape = getResources().getDrawable(R.drawable.normal_shape);
Drawable targetShape = getResources().getDrawable(R.drawable.target_shape);
@Override
public boolean onDrag(View v, DragEvent event) {
// Handles each of the expected events
switch (event.getAction()) {
//signal for the start of a drag and drop operation.
case DragEvent.ACTION_DRAG_STARTED:
// do nothing
break;
//the drag point has entered the bounding box of the View
case DragEvent.ACTION_DRAG_ENTERED:
//v.setBackground(targetShape);    //change the shape of the view
break;
//the user has moved the drag shadow outside the bounding box of the View
case DragEvent.ACTION_DRAG_EXITED:
break;
//drag shadow has been released,the drag point is within the bounding box of the View
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
// There is some code here
break;
//the drag and drop operation has concluded.
case DragEvent.ACTION_DRAG_ENDED:
//v.setBackground(normalShape);    //go back to normal shape
default:
break;
}
return true;
}
}
class MyClickListener implements View.OnTouchListener {
@Override
public boolean onTouch(View view, MotionEvent event) {
// TODO Auto-generated method stub
if (event.getAction() == MotionEvent.ACTION_DOWN) {
// create it from the object's tag
ClipData.Item item = new ClipData.Item((CharSequence) view.getTag());
String[] mimeTypes = {ClipDescription.MIMETYPE_TEXT_PLAIN};
ClipData data = new ClipData(view.getTag().toString(), mimeTypes, item);
View.DragShadowBuilder shadowBuilder = new View.DragShadowBuilder(view);
view.startDrag(data, //data to be dragged
shadowBuilder, //drag shadow
view, //local data about the drag and drop operation
0   //no needed flags
);
view.setVisibility(View.INVISIBLE);
return true;
}
else if (event.getAction() == MotionEvent.ACTION_UP){
view.setVisibility(View.VISIBLE);
return true;
}
else
{
return false;
}

}
}

构建分级如下所示。

apply plugin: 'com.android.application'
android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
defaultConfig {
applicationId "________"
minSdkVersion 16
targetSdkVersion 22
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
}
debug {
debuggable false
}
}
}
dependencies {
compile 'com.android.support:support-v4:23.0.0'
compile 'com.android.support:appcompat-v7:23.1.0'
}

在三星Galaxy S6(Android版本5.1.1)中拖放后,图像会消失。控制台中显示的错误是ViewRootImpl:报告丢弃结果:false该应用程序在任何其他设备上都没有问题。是 API 问题还是什么?供您参考,我检查了此解决方案,但这无法解决我的问题。

检查此代码,它将解决问题

` if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
view.startDragAndDrop(dragData, myShadow, null, 0);
} else {
view.startDrag(dragData, myShadow, null, 0);
}`

为了防止图像消失,我建议添加:

if (!isDropped) {
((View) dragEvent.getLocalState()).setVisibility(View.VISIBLE);
}

onDrag(...)方法的末尾,其中isDropped是声明为false的全局boolean变量,但在您的ACTION_DROP情况下使其等于true

相关内容

最新更新