ImageButton background with XML



I am trying to make a round Android ImageButton. To do so, I write the following code according to the link.


In my main.xml



<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/round"
android:background="@drawable/roundcorner"
android:padding="50dp" />


In my res/drawable/roundcorner.xml



<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://ift.tt/nIICcg">
<solid android:color="#33DDFF" />
<corners android:radius="100dp" />
</shape>


But the code doesn't work. The output is like below Image1


However, when I change ImageButton to ImageView in main.xml



<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton"
android:src="@drawable/round"
android:background="@drawable/roundcorner"
android:padding="50dp" />


It works as below


Image2


I am confused since as I know ImageButton inherits from ImageView. Why does it work differently? Is there anyway to fix this? Thanks in advance!


No comments:

Post a Comment