0

Is there something wrong with my code? round_corner.xml (I put it in drawable)

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

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="#FFFF0F" />
    <corners android:radius="30dp" />
    </shape>

I think what's not working is the code in my imageButton

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:padding="5dp">

    <ImageButton
        android:id="@+id/my_button"
        android:layout_width="match_parent"
        android:layout_height="170dp"
        android:layout_gravity="center"
        android:background="@drawable/round_corner"
        android:src="@drawable/my_pic"/>

    </LinearLayout>

It doesn't give me any error . It just didn't make my image rounded . Any ideas?

Manohar
  • 22,116
  • 9
  • 108
  • 144
user_22
  • 39
  • 6

2 Answers2

0

I suggest you use CardView instead of Image Button

You can achieve the same effect by CardView by this code.

<android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/my_pic"
        app:cardCornerRadius="30dp"/>
Bhuvanesh BS
  • 13,474
  • 12
  • 40
  • 66
0

First Create a shape.xml

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    <solid android:color="#FFFF0F" />
    <corners android:radius="30dp" />
    </shape>

use this xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/card_view"

    android:layout_width="match_parent"
    android:layout_height="120dp"
    android:layout_gravity="center"

    android:layout_margin="8dp"
    android:background="@drawable/shape"

    android:elevation="4dp">

    <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:elevation="4dp"
        app:cardCornerRadius="8dp">

        <ImageButton
            android:id="@+id/thumbnaill"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_gravity="left"
            android:background="@drawable/maxresdefault"
            android:scaleType="fitXY"
            />
    </android.support.v7.widget.CardView>
</LinearLayout>

Here is Your Output :) Please Note it will not show the radius on Xml preview run the app it will appear

Output

Faiz Mir
  • 599
  • 5
  • 16