android - ImageButton with different states images size -
how can prevent imagebutton
having fixed size? drawables used in selector have different size, , want imagebutton
resize match image size.
i've tried adjustviewbounds
without success.
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:padding="8dp" > <imagebutton android:id="@+id/picture_imagebutton" android:layout_width="wrap_content" android:layout_height="wrap_content" android:adjustviewbounds="true" android:src="@drawable/tab_background_selector" /> </relativelayout>
instead of using imagebutton
, utilize imageview
because imagebutton
cannot resized based on imagesize
. imageview
best alternative way can suggest problem. acheive next way:
layout.xml:
<relativelayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <imageview android:id="@+id/image" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/image_selection"/> </relativelayout>
image_selection.xml:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_focused="true" android:state_pressed="true" android:drawable="@drawable/default_image"/> //default_image.png displayed when activity loads. <item android:state_focused="false" android:state_pressed="true" android:drawable="@drawable/default_image_hover" /> //default_image_hover.png image displaed during onclick of imageview <item android:state_focused="true" android:drawable="@drawable/default_image_hover" /> <item android:state_focused="false" android:drawable="@drawable/default_image"/> </selector>
sampleactivity.java:
imageview myimage= (imageview)findviewbyid(r.id.image); myimage.setonclicklistener(this);
android android-layout imagebutton
No comments:
Post a Comment