Sto preparando i drawable per la mia applicazione. Ho un sacco di radiobutton, che vengono visualizzati come immagini con frame opzionale (quando selezionato). Si guarda disegnabili come la seguente:Riutilizzo di parti di Drawable su Android
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item>
<inset android:insetTop="@dimen/selectionBorderSize"
android:insetLeft="@dimen/selectionBorderSize"
android:insetRight="@dimen/selectionBorderSize"
android:insetBottom="@dimen/selectionBorderSize">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"></solid>
</shape>
</item>
<item>
<bitmap android:src="@drawable/sharp7" >
<padding android:bottom="@dimen/selectionBorderSize"
android:top="@dimen/selectionBorderSize"
android:left="@dimen/selectionBorderSize"
android:right="@dimen/selectionBorderSize" />
</bitmap>
</item>
</layer-list>
</inset>
</item>
</layer-list>
</item>
<item android:state_checked="false">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
<item>
<inset android:insetTop="@dimen/selectionBorderSize"
android:insetLeft="@dimen/selectionBorderSize"
android:insetRight="@dimen/selectionBorderSize"
android:insetBottom="@dimen/selectionBorderSize">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"></solid>
</shape>
</item>
<item>
<bitmap android:src="@drawable/sharp7" >
<padding android:bottom="@dimen/selectionBorderSize"
android:top="@dimen/selectionBorderSize"
android:left="@dimen/selectionBorderSize"
android:right="@dimen/selectionBorderSize" />
</bitmap>
</item>
</layer-list>
</inset>
</item>
</layer-list>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
</selector>
un altro:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="@color/colorPrimary" />
</shape>
</item>
<item>
<inset android:insetTop="@dimen/selectionBorderSize"
android:insetLeft="@dimen/selectionBorderSize"
android:insetRight="@dimen/selectionBorderSize"
android:insetBottom="@dimen/selectionBorderSize">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"></solid>
</shape>
</item>
<item>
<bitmap android:src="@drawable/sharp6" >
<padding android:bottom="@dimen/selectionBorderSize"
android:top="@dimen/selectionBorderSize"
android:left="@dimen/selectionBorderSize"
android:right="@dimen/selectionBorderSize" />
</bitmap>
</item>
</layer-list>
</inset>
</item>
</layer-list>
</item>
<item android:state_checked="false">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
<item>
<inset android:insetTop="@dimen/selectionBorderSize"
android:insetLeft="@dimen/selectionBorderSize"
android:insetRight="@dimen/selectionBorderSize"
android:insetBottom="@dimen/selectionBorderSize">
<layer-list>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff"></solid>
</shape>
</item>
<item>
<bitmap android:src="@drawable/sharp6" >
<padding android:bottom="@dimen/selectionBorderSize"
android:top="@dimen/selectionBorderSize"
android:left="@dimen/selectionBorderSize"
android:right="@dimen/selectionBorderSize" />
</bitmap>
</item>
</layer-list>
</inset>
</item>
</layer-list>
</item>
<item>
<shape android:shape="rectangle">
<solid android:color="#ffffff" />
</shape>
</item>
</selector>
Se non si vuole giocare "trovare 2 differenze", l'unica cosa che cambia è l'immagine in <bitmap>
tag.
Mi sento intere WET qui. C'è un modo per riutilizzare parte di questo drawable?
WET, ad es. non DRY