J'ai une classe qui étend FrameLayout appelé NoteView. C'est une classe publique de premier niveau.Comment utiliser Android ViewGroup personnalisé en XML?
Cela fonctionne très bien lorsque je crée l'interface utilisateur à partir du code Java, mais je n'arrive pas à comprendre comment l'utiliser en XML. J'ai essayé d'insérer le nom de classe entièrement qualifié comme je le ferais pour une vue personnalisée, mais je reçois et l'exception ClassCastException: android.view.View cannot be cast to android.view.ViewGroup
lorsque l'activité tente de gonfler le XML.
J'ai seulement été capable de trouver des tutoriels sur des vues personnalisées, pas des groupes de vue personnalisés. Que dois-je faire pour utiliser un NoteView comme je le ferais avec un FrameLayout dans une mise en page XML?
Par exemple: Cela fonctionne
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<test.cjb.sandbox.NoteView
android:id="@+id/noteview"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FF0000"
android:layout_gravity="right">
</test.cjb.sandbox.NoteView>
<Button
android:id="@+id/button"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:text="Sibling Button"/>
</LinearLayout>
Mais cela jette l'exception ci-dessus:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<test.cjb.sandbox.NoteView
android:id="@+id/noteview"
android:layout_width="fill_parent"
android:layout_height="100dp"
android:background="#FF0000"
android:layout_gravity="right">
<Button
android:id="@+id/button"
android:layout_width="100dp"
android:layout_height="fill_parent"
android:text="Child Button"/>
</test.cjb.sandbox.NoteView>
</LinearLayout>
Vous aurez peut-être plus de chance d'obtenir de l'aide si vous incluez la trace complète de la pile. – CommonsWare