Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
726 views
in Technique[技术] by (71.8m points)

imagebutton - Rounded corners android image buttons

I am trying to round corners on an android ImageButton, the code looks like this;

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent">

    <RelativeLayout 
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <ImageButton
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/imageButton"
            android:layout_marginTop="57dp"
            android:src="@drawable/friends"
            android:padding="1dp"
            android:layout_alignParentTop="true"
            android:layout_toLeftOf="@+id/imageButton2"
            android:layout_marginRight="62dp" />

    </RelativeLayout>
</LinearLayout>

Basically our output is an ImageButton but it has squared corners, we are trying to round off the corners.

Thanks

question from:https://stackoverflow.com/questions/21633637/rounded-corners-android-image-buttons

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Use Shape in android to make the rounder corners

create the xml file named it as 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="4dp" />
    </shape>

In your ImageButton add this attribute android:background="@drawable/roundcorner"

<ImageButton
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/imageButton"
                android:layout_marginTop="57dp"
                android:src="@drawable/friends"
                android:background="@drawable/roundcorner"
                android:padding="1dp"
                android:layout_alignParentTop="true"
                android:layout_toLeftOf="@+id/imageButton2"
                android:layout_marginRight="62dp" />

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...