Kawakuti
Kawakuti

Reputation: 64

draw a rectangle over image android

Hello I want draw a rectangle over an imageview . Like this

enter image description here

I created a shape drawable

    <?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle">
    <stroke
        android:dashGap="1dp"
        android:dashWidth="1dp"
         android:width="1dp"
        android:color="@color/divider_color"/>
    <padding
        android:bottom="5dp"
        android:left="5dp"
        android:right="5dp"
        android:top="5dp" />
</shape>

and i called like this on Layout.xml

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/retangle_line">

    <ImageView
        android:id="@+id/coverImageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:scaleType="centerCrop"
        />
</RelativeLayout>

But it generates this image enter image description here

Upvotes: 0

Views: 355

Answers (1)

tj2611
tj2611

Reputation: 327

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<ImageView
    android:id="@+id/coverImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:scaleType="centerCrop"
    />

<View 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@drawable/retangle_line"
    android:layout_margin="50dp"
    />

 </RelativeLayout>

Upvotes: 2

Related Questions