gpt4 book ai didi

android - GridLayout android.view.ViewGroup$LayoutParams 无法转换为 android.support.v7.widget.GridLayout$LayoutParams

转载 作者:搜寻专家 更新时间:2023-11-01 07:35:48 27 4
gpt4 key购买 nike

我将 GridLayout 作为 subview ,并设置了(空)GridLayout.LayoutParams

setLayoutParams(new GridLayout.LayoutParams());

我没有在其他任何地方将 LayoutParams 设置为此。但是我遇到了异常

E/AndroidRuntime( 1620): FATAL EXCEPTION: main
E/AndroidRuntime( 1620): java.lang.ClassCastException: android.view.ViewGroup$LayoutParams cannot be cast to android.support.v7.widget.GridLayout$LayoutParams
E/AndroidRuntime( 1620): at android.support.v7.widget.GridLayout.computeLayoutParamsHashCode(GridLayout.java:872)
E/AndroidRuntime( 1620): at android.support.v7.widget.GridLayout.checkForLayoutParamsModification(GridLayout.java:879)
E/AndroidRuntime( 1620): at android.support.v7.widget.GridLayout.onMeasure(GridLayout.java:927)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.support.v4.view.ViewPager.onMeasure(ViewPager.java:1249)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
E/AndroidRuntime( 1620): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1390)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.measureVertical(LinearLayout.java:681)
E/AndroidRuntime( 1620): at android.widget.LinearLayout.onMeasure(LinearLayout.java:574)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4814)
E/AndroidRuntime( 1620): at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
E/AndroidRuntime( 1620): at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2148)
E/AndroidRuntime( 1620): at android.view.View.measure(View.java:15172)
E/AndroidRuntime( 1620): at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1848)
E/AndroidRuntime( 1620): at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1100)
E/AndroidRuntime( 1620): at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1273)
E/AndroidRuntime( 1620): at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:998)
E/AndroidRuntime( 1620): at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4212)
E/AndroidRuntime( 1620): at android.view.Choreographer$CallbackRecord.run(Choreographer.java:725)
E/AndroidRuntime( 1620): at android.view.Choreographer.doCallbacks(Choreographer.java:555)
E/AndroidRuntime( 1620): at android.view.Choreographer.doFrame(Choreographer.java:525)
E/AndroidRuntime( 1620): at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:711)
E/AndroidRuntime( 1620): at android.os.Handler.handleCallback(Handler.java:615)
E/AndroidRuntime( 1620): at android.os.Handler.dispatchMessage(Handler.java:92)
E/AndroidRuntime( 1620): at android.os.Looper.loop(Looper.java:137)
E/AndroidRuntime( 1620): at android.app.ActivityThread.main(ActivityThread.java:4745)
E/AndroidRuntime( 1620): at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 1620): at java.lang.reflect.Method.invoke(Method.java:511)
E/AndroidRuntime( 1620): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:786)
E/AndroidRuntime( 1620): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
E/AndroidRuntime( 1620): at dalvik.system.NativeStart.main(Native Method)
W/ActivityManager( 304): Force finishing activity com.capsule.launcher/.LauncherActivity

为什么?

最佳答案

您是否通过了 GridLayout.LayoutParamsGridLayout本身?我认为这是不对的。

当您调用 setLayoutParams 时,您正在向父类提供有关如何布局特定子项的信息。你应该传递 <ParentClass>.LayoutParams到 GridLayout,其中 ParentClass是 GridLayout 所在的任何容器。

GridLayout.LayoutParams仅用于为 GridLayoutchildren 设置 layoutParams .

关于android - GridLayout android.view.ViewGroup$LayoutParams 无法转换为 android.support.v7.widget.GridLayout$LayoutParams,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11492665/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com