0
我正在開發一款包含拖放功能的遊戲。它適用於除Samsung Galaxy S6之外的所有設備。ViewRootImpl:在三星Galaxy S6上報告投遞結果:false
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;
}
}
}
構建gradle看起來像這樣。
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問題還是什麼?爲了您的信息,我檢查了這個solution,但這不能解決我的問題。