2

I am a beginner to android studio and I need to fit a png image to a shape I defined in res/drawable as an xml file

<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/listview_background_shape">
    <stroke android:width="2dp" android:color="#ff207d94" />
    <padding android:left="2dp"
        android:top="2dp"
        android:right="2dp"
        android:bottom="2dp" />

    <corners android:bottomLeftRadius="150dp"
        android:topLeftRadius="20dp"
        android:topRightRadius="20dp"
        android:bottomRightRadius="20dp"/>
    <solid android:color="#ffffffff" />
</shape>

The shape looks like this,

enter image description here

I need to fit a rectangular image to it but don't know how to do so. The output should somewhat look like this

enter image description here

Related: Add a background image to shape in XML Android I have tried using the code in the link but no luck.

Edit: The activity_main.xml file with ImageView is

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

    <ImageView
        android:id="@+id/imageView"
        android:layout_width="fill_parent"
        android:layout_height="300dp"
        android:background="@drawable/shape"
        android:src="@drawable/test"/>
</LinearLayout>

The output of the above file is,

enter image description here

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
kunal
  • 365
  • 1
  • 4
  • 16

0 Answers0