2

I am trying to make my image with round corners. I am doing like this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:drawable="@drawable/bg" />
    <item>

        <shape android:shape="rectangle" android:padding="10dp">
            <solid android:color="#00000000" />
            <corners
                android:bottomRightRadius="15dp"
                android:bottomLeftRadius="15dp"
                android:topLeftRadius="15dp"
                android:topRightRadius="15dp"/>
            <stroke android:width="3dp" android:color="#a9a9a9"/>
        </shape>
    </item>

</layer-list>

and result is like this

enter image description here

You can see there grey color behind round corner, How I can remove it? I think I am missing something. Let me know if someone can help me for solve my issue. Thanks

Priya
  • 47
  • 1
  • 6

3 Answers3

4

You can use cardView to make corner rounded try this one

   <android.support.v7.widget.CardView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:cardCornerRadius="8dp"
        android:layout_margin="5dp"
        android:elevation="10dp">

        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/bg"
            android:scaleType="centerCrop"
            />
    </android.support.v7.widget.CardView>

In your code remove

         <stroke android:width="3dp" android:color="#a9a9a9"/>

then you can remove grey color border

  • I need icon and text in that background, so I think cardview can not help me for achieve it. Let me know what You say. Thanks! – Priya Jan 26 '20 at 03:11
  • Ah k, if you need to remove grey color corner try to remove attribute and check – waseem akram Jan 26 '20 at 03:32
  • @Priya it is possible to achieve this effect by using a cardview. Just add a RelativeLayout to the CardView and then you can easily add an icon and a text in the background. – Lukas Jan 26 '20 at 09:20
1

I don't know if the corner space is removable or not. But you can use a mask as the foreground to your image view. Use the xml below to create a mask.

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
        <shape android:shape="rectangle">
            <stroke
                android:color="#555555"
                android:width="5dp"/>
        </shape>

</item>
<item android:top="-1dp" android:bottom="-1dp"  android:right="-1dp" android:left="-1dp">
        <shape android:shape="rectangle">
            <stroke
                android:color="#555555"
                android:width="6dp"/>
            <corners android:radius="16dp"/>
        </shape>
</item>

Now if your minimum SDK version is 23 then you can just set the drawable as the foreground.

android:foreground="@drawable/mask"

But if you are targeting below 23 then you can try the code below.

<FrameLayout
    android:layout_margin="16dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <ImageView
        android:id="@+id/thumbImage"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/top_tracks_song" />

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@drawable/test">
    </FrameLayout>

</FrameLayout>
0

try this

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"
    >
    <item>
        <shape android:shape="rectangle">
            <solid android:color="#398B27"/>
            <corners android:radius="15dp" />
        </shape>

    </item>

    <item
        android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp">
        <shape android:shape="rectangle">
            <solid android:color="@android:color/white"/>
            <corners android:radius="15dp" />
        </shape>

    </item>

</layer-list>

Adjust

android:left="1dp"
        android:right="1dp"
        android:top="1dp"
        android:bottom="1dp"

this to get desire width


<ImageView
android:id="@+id/make_msg_attach"
android:layout_width="match_parent"
android:layout_height="200dp"
android:src="@drawable/my_image"
android:layout_margin="5dp"
android:background="@drawable/this_xml_file.xml"
android:padding="2dp"
/>

Arup
  • 54
  • 1
  • 8