J'ai une question sur les déclarations XML personnalisées.
J'ai créé ma propre vue avec les attributs personnalisés comme d'habitude. Maintenant, je veux ajouter des attributs plus complexes comme celui-ci: (ce code est non-travail)Attributs complexes dans Android Custom View XML
<com.xxx.yyy.CustomTextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/customTextView1"
android:layout_marginBottom="22dp"
android:layout_toRightOf="@+id/buttonBlack"
android:text="TextView" >
<Animation
animation:property1="123"
animation:property2="456" />
<Animation
animation:property1="789"
animation:property2="012" >
</Animation>
</com.xxx.yyy.CustomTextView>
Je ne ai pas trouvé un moyen de le faire moi-même, mais peut-être quelqu'un a eu une idée.
Merci!
Edit:
Je viens de résoudre le problème plus ou moins bien. J'ai créé un nouveau fichier .xml dans mon/res/dossier xml appelé animations.xml
<animations>
<animation
name="Animation name 1"
float1="1.1"
float2="1.2"
integer1="11"
integer2="12" />
<animation
name="Animation name 2"
float1="2.1"
float2="2.2"
integer1="21"
integer2="22" />
</animations>
Mon point de vue personnalisé dans attrs.xml contient un attribut qui est utilisé pour référencer le fichier ci-dessus animations.xml de:
<declare-styleable name="MyTextView">
<attr name="animations" format="reference" />
</declare-styleable>
maintenant, je parse le fichier .xml référencé dans le constructeur de l'MyTextView comme décrit ici: http://thedevelopersinfo.com/2009/12/14/using-xml-file-resources-in-android/
Peut-être que cela aide quelqu'un à un moment donné.
Vous devriez créer des attributs XML personnalisés pour cela comme décrit ici: http://developer.android.com/training/custom-views/create-view.html#applyattr – JimmyVanBraun