2014-06-26 2 views
2

J'essaie d'utiliser une disposition relative dans un tiroir afin de pouvoir inclure une vue de liste et une vue de grille. Réception l'erreur suivante lors de l'exécution:Disposition relative dans la disposition des tiroirs: les paramètres de disposition relative ne peuvent pas être transtypés dans les paramètres de disposition du tiroir

Logcat Erreur:

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> 
+0

après la pile pleine erreur trace – Javanator

+0

Hey, vous étiez en mesure de résoudre ce ?? –

Répondre

0

Utilisation:

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

Vous utilisez:

DrawerLayout mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_relative_layout); 

DrawerLayout est toujours gonflé à partir de la vue android.support.v4.widget.DrawerLayout et non de la disposition que vous incluez dans le tiroir.

+0

J'ai utilisé drawer_layout dans mon activité principale. – rahul

+0

pouvez-vous partager votre code d'activité principal pertinent. –

1

Veuillez vérifier votre code java. Assurez-vous d'utiliser les bons paramètres de mise en page. Vous pourriez faire référence à des mises en page autres que la disposition de votre tiroir.

peut se produire ici:

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

Ou ici:

drawerLayout.closeDrawer(drawerLayout); 
1

Je viens de courir complète POC faire un essai, ici est la mise en page

<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" > 

<!-- 
    As the main content view, the view below consumes the entire 
    space available using match_parent in both dimensions. 
--> 

<FrameLayout 
    android:id="@+id/content_frame" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" /> 

<!-- 
    android:layout_gravity="start" tells DrawerLayout to treat 
    this as a sliding drawer on the left side for left-to-right 
    languages and on the right side for right-to-left languages. 
    The drawer is given a fixed width in dp and extends the full height of 
    the container. A solid background is used for contrast 
    with the content view. 
--> 

<LinearLayout 
    android:id="@+id/left_drawer" 
    android:layout_width="220dp" 
    android:layout_height="match_parent" 
    android:layout_gravity="start" 
    android:orientation="vertical" > 

    <RelativeLayout 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_gravity="start" 
     android:orientation="vertical" 
     android:background="@android:color/holo_orange_light"> 

     <ImageView 
      android:id="@+id/ivwLogo" 
      android:layout_width="40dp" 
      android:layout_height="40dp" 
      android:src="@drawable/medicinecarticon" /> 

     <CheckBox 
      android:id="@+id/jji" 
      android:layout_width="wrap_content" 
      android:layout_height="40dp" 
      android:layout_toRightOf="@+id/ivwLogo" 
      android:text="huhuuhul" /> 
    </RelativeLayout> 

    <ListView 
     android:id="@+id/left_drawer_child" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:background="@android:color/white" 
     android:choiceMode="singleChoice" 
     android:divider="@android:color/transparent" 
     android:dividerHeight="0dp" /> 
</LinearLayout> 

Pour l'activité principale télécharger s'il vous plaît base de code complet https://drive.google.com/file/d/0B_1gIYJI3B4FWDE0bGpMZnhGQmc/view?usp=sharing projet complet espoir Téléchargé qui aidera

Questions connexes