1

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

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_gravity="center"
        android:textColor="#333"
        android:textSize="18sp"
        android:text="Invite Activity."  />

    <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"  />

</LinearLayout>

In my res/drawable/roundcorner.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
    <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!

Community
  • 1
  • 1
pp31630
  • 41
  • 7

1 Answers1

0

Make your src as android:src="@drawable/roundcorner", or make it transparent so you can see the rounded background behind it.

Sunit2k15
  • 11
  • 2
  • The result is like [this](http://imgur.com/YQMtoKy). So it seems that the big image cover up the button... is there a way to make the image fit the round button (crop the image to fit the round button)? – pp31630 Dec 25 '14 at 10:20
  • Check this if you want the same like imageview output. – Sunit2k15 Dec 26 '14 at 11:39