2012-04-03 89 views
-1

我正在开发一个包含许多自定义按钮的android应用程序。我是否需要为每个文件创建一个.xml文件,或者是否有将所有这些文件放入一个.xml文件的方法?有没有什么办法可以将我的自定义按钮放在android中的一个XML文件中?

<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
<item android:state_pressed="true" android:drawable="@drawable/father2" ></item> 
    <item android:drawable="@drawable/father" ></item> 

我可以使用多种自定义按钮的代码在一个XML文件?

<animation-list xmlns:android="http://schemas.android.com/apk/res/android" 
android:oneshot="false" > 
<item android:drawable="@drawable/brother1" android:duration="200"/> 
<item android:drawable="@drawable/brother2" android:duration="200"/> 
<item android:drawable="@drawable/brother3" android:duration="200"/> 
<item android:drawable="@drawable/brother4" android:duration="200"/> 
<item android:drawable="@drawable/brother5" android:duration="200"/> 

而且我也有一个动画列表;我可以在一个XML文件中使用多个动画列表吗?

+0

的你想什么来实现,将有助于得到更好的答案 – 2012-04-03 21:58:29

回答

1

这取决于你的按钮部分定制。如果只图像或文字的自定义,你可以把他们的res/styles.xml内,然后theme您在使用这些主题的其他布局中的XML内创建Button秒。

<LinearLayout ... > 
    <!--stuff--> 
    <Button style="@style/customButtonStyle1" ... other attributes /> 
</LinearLayout> 

如果他们有不同的状态(例如,按下,选择,未选择的),你可以使用一个<selector>资源分配值(图片,文字),以不同的状态。快速谷歌显示this选择器教程。

+0

我使用的选择,我有多个按钮,当按下按钮将变为另一个图像的例子。难道我用这个选择对所有的按钮,或者我应该使用不同的选择对于每一个和那肯定这么难,因为我有可能超过50个按钮 – Nada 2012-04-06 13:51:46

+0

我想你可以申请选择,只是按钮本身(即,做起来很如果您不关心按钮上的实际图像具有不同的选择状态,则按钮颜色会在通过选择器按下时改变)。如果你想为每个图像选择不同的状态,你需要为每个图像选择一个选择器。 – 2012-04-06 15:54:26

相关问题