Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use XML layout as drawable image

I would like to add an XML Layout as drawable image for GalleryView. Is it possible? here is the scenario, I'm having one Layout in my application. I would like to use images for my gallery, those images exactly looking like the XML layout(but background and some other views color will be different). So instead of creating multiple images for gallery, I want to use these xml layout as drawables in Gallery view. Is it possible,? If so how to do that? please help me out friends.

like image 632
Andro Dev Avatar asked Nov 13 '22 01:11

Andro Dev


1 Answers

See i have create XML like this

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<item android:drawable="@drawable/always_over" android:state_enabled="false"/>
<item android:drawable="@drawable/always_over" android:state_enabled="true" android:state_pressed="true"/>
<item android:drawable="@drawable/always_over" android:state_enabled="true" android:state_focused="true"/>
<item android:drawable="@drawable/always" android:state_enabled="true"/>

</selector>

And then set in Button

   <Button
        android:id="@+id/btnAlways"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/always_xml" />
like image 114
Nirali Avatar answered Jan 09 '23 04:01

Nirali