Home > Software engineering >  Android: corner border stroke getting hidden behind imageview
Android: corner border stroke getting hidden behind imageview

Time:10-27

hello I'm trying to add a corner to my constraint layout so the logic is whenever from the response I'm not getting the image I will show text else image but whenever the image comes corner stroke is getting hidden in the imageview

problem image:-

enter image description here

here is my code:

   <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/constraint_rt"
        android:layout_width="0dp"
        android:layout_height="@dimen/_115sdp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="W,16:9"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:padding="1dp"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/rt_list_img_gradient_bg_with_stroke"
        android:orientation="vertical">

        <TextView
            android:id="@ id/txtpopularRT"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/worksans_semibold"
            android:gravity="center"
            android:textColor="@color/klgreen"
            android:textSize="@dimen/_12ssp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@ id/imageRt"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:visibility="gone" />
    </androidx.constraintlayout.widget.ConstraintLayout>

drawable file:-

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<gradient
    android:startColor="@color/black"
    android:endColor="@color/new_black_1"
    android:angle="270" />
<stroke android:width="2dp" android:color="@color/kred" />
<corners
    android:radius="10dp">
</corners>

please help me out with how can I show the stroke at the corner

any help will be appreciated

CodePudding user response:

Your Image is hiding stroke border because your drawable or background shape of constraint layout have corners radius so if you notice in your image only corner parts are being hidden so you can fix by also adding corners to image. You can do by wrapping ImageView in CardView and giving corner radius to that cardview something like this -

UPDATED CODE :

   <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@ id/constraint_rt"
        android:layout_width="0dp"
        android:layout_height="@dimen/_115sdp"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintDimensionRatio="W,16:9"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:padding="1dp"
        app:layout_constraintTop_toTopOf="parent"
        android:background="@drawable/rt_list_img_gradient_bg_with_stroke"
        android:orientation="vertical">

        <TextView
            android:id="@ id/txtpopularRT"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:fontFamily="@font/worksans_semibold"
            android:gravity="center"
            android:textColor="@color/klgreen"
            android:textSize="@dimen/_12ssp"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.cardview.widget.CardView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:cardCornerRadius="10dp">

             <ImageView
              android:id="@ id/imageRt"
              android:layout_width="match_parent"
              android:layout_height="match_parent"
              android:adjustViewBounds="true"
              android:scaleType="fitXY"
              android:visibility="gone" />
    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

INFO :

I have added 10dp of corner radius because your shape drawable have the same radius - 10dp.

P.S - Alternative You can also use RoundedImageView

  • Related