Android 拖放操作不需要';有些设备不能正常工作

Android 拖放操作不需要';有些设备不能正常工作,android,drag-and-drop,Android,Drag And Drop,我创建了一个简单的拖放游戏应用程序,用户需要从堆栈中拖动一张卡,并将其放入正确的类别槽中。我的问题是,当我在三台设备上测试应用程序时,两台设备通过了测试,但一台设备失败。这台设备的问题是,即使将卡正确拖动到正确的类别插槽中,类别插槽也不会接受该卡。logcat中的结果返回了false,而不是true 02-01 21:13:03.219 25955-25971/com.theothercard.dragdrop I/art: Background sticky concurrent mark s

我创建了一个简单的拖放游戏应用程序,用户需要从堆栈中拖动一张卡,并将其放入正确的类别槽中。我的问题是,当我在三台设备上测试应用程序时,两台设备通过了测试,但一台设备失败。这台设备的问题是,即使将卡正确拖动到正确的类别插槽中,类别插槽也不会接受该卡。logcat中的结果返回了
false
,而不是
true

02-01 21:13:03.219 25955-25971/com.theothercard.dragdrop I/art: Background sticky concurrent mark sweep GC freed 7750(606KB) AllocSpace objects, 1(12KB) LOS objects, 5% free, 10MB/11MB, paused 11.205ms total 47.587ms
02-01 21:13:03.459 25955-25955/com.theothercard.dragdrop D/android.support.v7.widget.GridLayout: horizontal constraints: x1-x0>=192, x2-x1>=192, x3-x2>=192, x4-x3>=182, x4-x0<=749 are inconsistent; permanently removing: x4-x0<=749. 
02-01 21:13:18.059 25955-25955/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false
02-01 21:13:21.139 25955-25955/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false
02-01 21:13:30.119 25955-25955/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false
以下是
placeCard()

我真的不知道现在该怎么办。我感谢你的帮助

其他信息:我尝试过并获得成功结果的设备是运行棉花糖的Redmi Note 3 Pro和运行棉花糖的Galaxy Note 8.0。失败的是运行棒棒糖的Zenfone 5

更新:因为我正在比较两个恒定状态以获得正确的图像,这里是logcat

使用Redmi Note 3运行棉花糖进行测试:

2-01 21:55:30.616 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.616 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@8b65297
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@a955c84
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@5e0cc6d
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.618 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@84e70a2
02-01 21:55:30.618 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.619 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@f038133
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@64dbcf0
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@4ac269
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@d46f4ee
02-01 21:55:30.622 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.622 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.624 11714-11714/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: true
使用Zenfone 5运行棒棒糖测试类似图像:

02-01 21:58:11.908 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@2d5b7e1e
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@33cdccc
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@15bd5e2a
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@13c0f9b8
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3aab32f6
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@c67f964
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@fcf8882
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@e5d47d0
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@26f1aace
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@201710fc
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@1501a5da
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@174240e8
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false
这里主要关心的是为什么后者没有任何类似的ConstantState,或者我做错了


谢谢你的帮助

Nvm我通过参考解决了这个问题。换衣服

 if (draggedImage.getDrawable().getConstantState().equals(
            getResources().getDrawable(Card.cards[card].getCardResId()).getConstantState())) {}

placeCard()
方法中

基本上从API 21开始,您必须使用
ContextCompat.getDrawable()
而不是普通的
getResources().getDrawable()
方法

2-01 21:55:30.616 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.616 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@8b65297
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@a955c84
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@5e0cc6d
02-01 21:55:30.617 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.618 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@84e70a2
02-01 21:55:30.618 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.619 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@f038133
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@64dbcf0
02-01 21:55:30.620 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@4ac269
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.621 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@d46f4ee
02-01 21:55:30.622 11714-11714/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.622 11714-11714/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@b55d916
02-01 21:55:30.624 11714-11714/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: true
02-01 21:58:11.908 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@2d5b7e1e
02-01 21:58:11.918 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@33cdccc
02-01 21:58:11.938 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@15bd5e2a
02-01 21:58:11.958 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@13c0f9b8
02-01 21:58:11.978 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3aab32f6
02-01 21:58:11.998 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@c67f964
02-01 21:58:12.018 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@fcf8882
02-01 21:58:12.038 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@e5d47d0
02-01 21:58:12.058 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@26f1aace
02-01 21:58:12.078 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@201710fc
02-01 21:58:12.088 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@1501a5da
02-01 21:58:12.108 25079-25079/com.theothercard.dragdrop D/DRAGGED IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@3d9aef58
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop D/ORIGINAL IMAGE: android.graphics.drawable.BitmapDrawable$BitmapState@174240e8
02-01 21:58:12.138 25079-25079/com.theothercard.dragdrop I/ViewRootImpl: Reporting drop result: false
 if (draggedImage.getDrawable().getConstantState().equals(
            getResources().getDrawable(Card.cards[card].getCardResId()).getConstantState())) {}
if (draggedImage.getDrawable().getConstantState().equals(
                ContextCompat.getDrawable(GameActivity.this, Card.cards[card].getCardResId()).getConstantState())) {