android - 抽屉布局内的相对布局: relative layout params cannot be cast into drawer layout params

标签 android android-layout layout android-relativelayout

我正在尝试在抽屉内使用相对布局,以便可以包含 ListView 和 GridView 。运行时收到以下错误:

Logcat 错误:

java.lang.ClassCastException: android.widget.RelativeLayout$LayoutParams cannot be cast to android.support.v4.widget.DrawerLayout$LayoutParams

XML:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!-- Framelayout to display Fragments -->
    <FrameLayout
        android:id="@+id/frame_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />


    <!-- ListView to display slider menu -->
   <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="240dp"
        android:layout_height="fill_parent"
         android:layout_gravity="start"
        android:id="@+id/drawer_relative_layout"
        >
    <ListView
        android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:divider="@color/list_divider"
        android:dividerHeight="1dp"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"      
        android:listSelector="@drawable/list_selector"
        android:background="@color/list_background"         
     />
       <GridView
        android:id="@+id/images_drawer"
        android:layout_width="240dp"
        android:layout_height="fill_parent"
        android:layout_below="@id/left_drawer"
        android:layout_gravity="left"
        android:choiceMode="singleChoice"      
        android:background="@color/list_background"
        android:layout_margin="5dp"
        android:columnWidth="100dp"
        android:drawSelectorOnTop="true"
        android:numColumns="2"
        android:stretchMode="columnWidth"
        android:horizontalSpacing="5dp"
        android:verticalSpacing="5dp"
         />
   </RelativeLayout>

</android.support.v4.widget.DrawerLayout>

最佳答案

请检查您的java代码。确保您使用正确的布局参数。您可能指的是抽屉布局以外的布局。

可能发生在这里:

DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);

或者在这里:

drawerLayout.closeDrawer(drawerLayout);

关于android - 抽屉布局内的相对布局: relative layout params cannot be cast into drawer layout params,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24428937/

相关文章:

android - 如何将滑动选项卡 View 放入抽屉导航选项之一

android - RecyclerView IndexOutOfBoundsException异常

java - 为什么在 Android studio 中工作时无法获得清晰的图像?

java - 当我想要执行新任务时,我的 Android 应用程序就会崩溃

android - 如何在 RelativeLayout 中的图像上写入文本,同时它始终保持相同的位置(即使调整图像大小)?

android-layout - 创建全景 View android

css - 子 div 比父 div 宽但在父 div 之后。有没有办法做到这一点?

android - RecyclerView onMeasure 性能问题

带有图像的 Jquery 砌体中心布局不适用于加载

ios - 如何使用 Xcode Storyboard 保持导入图像的原始尺寸?