This is a very late "me too", but, coming to this and other issues that were looking for a solution, I found a simple, elegant solution.
Another question complained that the transparent background of their image is not clickable. If this is a problem, it seems to work around this too.
Here is the button:
<ImageButton android:id="@+id/arrowUp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/arrow_up" android:background="@drawable/clear_button_background" />
The corresponding lines are the last two. "@drawable/arrow_up" are several button states in * .png files defined in a * .xml file with the ability to cut:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:state_pressed="true" android:drawable="@drawable/tri_up_blue" /> <item android:state_selected="true" android:drawable="@drawable/tri_up_blue" /> <item android:state_focused="true" android:drawable="@drawable/tri_up_blue" /> <item android:drawable="@drawable/tri_up_green" /> </selector>
Just your main button. Nothing special. And "@drawable/clear_button_background" is only:
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle"> <solid android:color="@android:color/transparent"/> <size android:width="20dp" android:height="30dp" /> </shape>
The height and width here are the area that can be clicked, resize if necessary. You can use it as many times as needed in one view, unlike the absurdly detailed TouchDelegate. No additional listeners. It does not add any views or groups to your hierarchy, and you will not be busy with the filling and fields all day.
Simple Elegant.
anthropomo Jan 13 '13 at 3:07 2013-01-13 03:07
source share