我對自定義視圖XML聲明有個疑問。
我用正常的自定義屬性創建了自己的View。現在,我想補充這樣的更復雜的屬性:(這是不工作的代碼)Android自定義視圖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>
我沒有找到一個方法來做到這一點對我自己的,但也許有人已經有了一個主意。
謝謝!
編輯:
我只是解決了這個問題或多或少很好。
: 我叫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>
在attrs.xml我的自定義視圖中包含用於從上述引用animations.xml文件的屬性我/ RES/XML文件夾中創建一個新的.xml文件
<declare-styleable name="MyTextView">
<attr name="animations" format="reference" />
</declare-styleable>
現在我解析引用的.xml文件在MyTextView的構造如下所述:http://thedevelopersinfo.com/2009/12/14/using-xml-file-resources-in-android/
也許這可以幫助別人,在一段時間。
您應該爲此創建自定義XML屬性,如此處所述:http://developer.android.com/training/custom-views/create-view.html#applyattr – JimmyVanBraun