我有两个ViewGroup
只包含ImageView
个。一个ViewGroup
(RecyclerView
)类似于工具箱。另一个是工作区(RelativeLayout
)。我需要从工具箱中拖出ImageView
并将其拖放到工作区。
我试图将整个ImageView从一个父级移动到另一个父级。
case DragEvent.ACTION_DROP:
View view = (View) event.getLocalState();
ViewGroup owner = (ViewGroup) view.getParent();
owner.removeView(view);
RelativeLayout container = (RelativeLayout) layoutview;
container.addView(view);
view.setVisibility(View.VISIBLE);
break;
这适用于Android下面的7.1.1以及2月更新。但是在2月7日1日,我有一个例外:
ClassCastException:android.widget。 RelativeLayout的$的LayoutParams 无法转换为android.support.v7.widget.RecyclerView $ LayoutParams
它出现在view.setVisibility()
中。在调试器中我可以看到,删除后,ImageView
在父级中有RelativeLayout
,在layoutParams中有RelativeLayout.LayoutParams
。但是当视图调用其setVisibility
时,则RecycleView
布局会运行。
为什么此异常仅在2月7.1.1更新时抛出?我该怎么办?也许我应该只移动数据而不是整个视图?但是我必须在工作区域中创建一个新的ImageView
。
UPD: Logcat:
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.alexander.example, PID: 20588
java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v7.widget.RecyclerView$LayoutParams
at android.support.v7.widget.RecyclerView.getChildViewHolderInt(RecyclerView.java:4226)
at android.support.v7.widget.RecyclerView$LayoutManager.onInitializeAccessibilityNodeInfoForItem(RecyclerView.java:9406)
at android.support.v7.widget.RecyclerViewAccessibilityDelegate$1.onInitializeAccessibilityNodeInfo(RecyclerViewAccessibilityDelegate.java:90)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.onInitializeAccessibilityNodeInfo(AccessibilityDelegateCompat.java:246)
at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.onInitializeAccessibilityNodeInfo(AccessibilityDelegateCompatJellyBean.java:66)
at android.view.View.onInitializeAccessibilityNodeInfo(View.java:6607)
at android.view.View.createAccessibilityNodeInfoInternal(View.java:6568)
at android.view.View$AccessibilityDelegate.createAccessibilityNodeInfo(View.java:23638)
at android.view.View.createAccessibilityNodeInfo(View.java:6551)
at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:145)
at android.view.accessibility.AccessibilityRecord.setSource(AccessibilityRecord.java:119)
at android.view.View.onInitializeAccessibilityEventInternal(View.java:6505)
at android.view.View$AccessibilityDelegate.onInitializeAccessibilityEvent(View.java:23550)
at android.support.v4.view.AccessibilityDelegateCompatIcs.onInitializeAccessibilityEvent(AccessibilityDelegateCompatIcs.java:97)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateIcsImpl.onInitializeAccessibilityEvent(AccessibilityDelegateCompat.java:192)
at android.support.v4.view.AccessibilityDelegateCompat.onInitializeAccessibilityEvent(AccessibilityDelegateCompat.java:432)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.onInitializeAccessibilityEvent(AccessibilityDelegateCompat.java:241)
at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.onInitializeAccessibilityEvent(AccessibilityDelegateCompatJellyBean.java:61)
at android.view.View.onInitializeAccessibilityEvent(View.java:6491)
at android.view.View.sendAccessibilityEventUncheckedInternal(View.java:6358)
at android.view.View$AccessibilityDelegate.sendAccessibilityEventUnchecked(View.java:23489)
at android.support.v4.view.AccessibilityDelegateCompatIcs.sendAccessibilityEventUnchecked(AccessibilityDelegateCompatIcs.java:122)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateIcsImpl.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:223)
at android.support.v4.view.AccessibilityDelegateCompat.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:371)
at android.support.v4.view.AccessibilityDelegateCompat$AccessibilityDelegateJellyBeanImpl$1.sendAccessibilityEventUnchecked(AccessibilityDelegateCompat.java:268)
at android.support.v4.view.AccessibilityDelegateCompatJellyBean$1.sendAccessibilityEventUnchecked(AccessibilityDelegateCompatJellyBean.java:87)
at android.view.View.sendAccessibilityEventUnchecked(View.java:6341)
at android.view.View$SendViewStateChangedAccessibilityEvent.run(View.java:23675)
at android.view.View$SendViewStateChangedAccessibilityEvent.runOrPost(View.java:23708)
at android.view.View.notifyViewAccessibilityStateChangedIfNeeded(View.java:9475)
at android.view.View.setFlags(View.java:11591)
at android.view.View.setVisibility(View.java:8069)
at android.widget.ImageView.setVisibility(ImageView.java:1551)
at com.alexander.example.CustomRelativeLayout.onDragEvent(CustomRelativeLayout.java:353)
at android.view.View.callDragEventHandler(View.java:20901)
at android.view.View.dispatchDragEvent(View.java:20889)
at android.view.ViewGroup.dispatchDragEvent(ViewGroup.java:1441)
at com.alexander.example.CustomRelativeLayout.dispatchDragEvent(CustomRelativeLayout.java:275)