Question

I am trying to create a ImageButton for my user portrait.

<ImageButton
    android:id="@+id/new_question_user_portrait"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:background="@drawable/oler_login_submit_button_bg"
    android:src="@drawable/oler_portrait"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="10dp"/>

This is the background xml file.

<?xml version="1.0" encoding="utf-8"?>
<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <corners android:radius="10dp" />
</shape>

My src image is 200*200 px. Round Corner still not working for these code.

Could anyone show me the correct way to create a rounded Image Button with fixed height and width regardless of image source?

Was it helpful?

Solution

You are expecting the background drawable to work as a mask, which it does not. The drawable is drawn behind the bitmap (after all, it's a background), so it's invisible.

What you are looking for is a mask, have a look at this question and its answers: Mask ImageView with round corner background

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top