1

i want to ask help for how to add vertical line in left side of cardview?

Current result

Vertical line move outside card view

Expected result Vertical line fit with card view

This is the code

<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView         
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/cvRoot"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    app:cardBackgroundColor="@color/lightPink"
    app:cardCornerRadius="@dimen/spacing_x">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:id="@+id/clContainer"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <View
            android:id="@+id/viewLine"
            android:layout_width="@dimen/spacing"
            android:layout_height="0dp"
            android:background="@color/coral"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.appcompat.widget.AppCompatImageView
            android:id="@+id/ivLogo"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_marginStart="@dimen/spacing_h"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toRightOf="@id/viewLine"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_error_rounded" />

        <androidx.constraintlayout.widget.Group
            android:id="@+id/groupDate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:visibility="visible"
            app:constraint_referenced_ids="tvTitle,tvSubTitle" />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/tvTitle"
            style="@style/TextParagraph2.Medium"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/spacing"
            android:layout_marginTop="@dimen/spacing_h"
            android:layout_marginEnd="@dimen/spacing_x"
            android:textColor="@color/darkGreyBlue"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintStart_toEndOf="@+id/ivLogo"
            app:layout_constraintTop_toTopOf="parent"
            tools:text="Sorry, it’s not you, It’s us." />

        <androidx.appcompat.widget.AppCompatTextView
            android:id="@+id/tvSubTitle"
            style="@style/TextParagraph3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginStart="@dimen/spacing"
            android:layout_marginTop="@dimen/spacing_small_x"
            android:layout_marginEnd="@dimen/spacing_x"
            android:layout_marginBottom="@dimen/spacing_h"
            android:textColor="@color/darkGreyBlue"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0"
            app:layout_constraintStart_toEndOf="@+id/ivLogo"
            app:layout_constraintTop_toBottomOf="@id/tvTitle"
            tools:text="Internal server problem. Please try again later" />

    </androidx.constraintlayout.widget.ConstraintLayout>

</androidx.cardview.widget.CardView>

Is my code correct, if not please tell me ?

I already try many ways but still not find the match solution, If you know how fix this issue, please comment bellow, thanks

sorry for my bad english

Ahmad Dudayef
  • 45
  • 2
  • 9
  • i thinks i found the solution from this thread https://stackoverflow.com/questions/53991918/how-i-can-clipping-vertical-line-in-a-cardview – Ahmad Dudayef Jun 11 '20 at 23:59

1 Answers1

1

I took your code and ran it. You are using AppCompat libraries, I'm not sure if that was the problem but I'm using androidx and it seems to work well. I just added some dummy properties for color and dimensions.

This is my result:

enter image description here

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/frameLayout9"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".fragments.maincontent.DummyFragment">

    <androidx.cardview.widget.CardView
        android:id="@+id/cvRoot"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        app:cardBackgroundColor="@color/colorPrimary"
        app:cardCornerRadius="15dp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <androidx.constraintlayout.widget.ConstraintLayout
            android:id="@+id/clContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <View
                android:id="@+id/viewLine"
                android:layout_width="20dp"
                android:layout_height="0dp"
                android:background="@color/gradientEndNoDarkMode"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toTopOf="parent" />

            <androidx.appcompat.widget.AppCompatImageView
                android:id="@+id/ivLogo"
                android:layout_width="20dp"
                android:layout_height="20dp"
                android:layout_marginStart="8dp"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintLeft_toRightOf="@id/viewLine"
                app:layout_constraintTop_toTopOf="parent"
                app:srcCompat="@drawable/ic_error_rounded" />

            <androidx.constraintlayout.widget.Group
                android:id="@+id/groupDate"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:visibility="visible"
                app:constraint_referenced_ids="tvTitle,tvSubTitle" />

            <TextView
                android:id="@+id/tvTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:textColor="@color/black"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0"
                app:layout_constraintStart_toEndOf="@+id/ivLogo"
                app:layout_constraintTop_toTopOf="parent"
                tools:text="Sorry, it’s not you, It’s us." />

            <TextView
                android:id="@+id/tvSubTitle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="8dp"
                android:layout_marginTop="8dp"
                android:layout_marginEnd="8dp"
                android:layout_marginBottom="8dp"
                android:textColor="@color/black"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintHorizontal_bias="0"
                app:layout_constraintStart_toEndOf="@+id/ivLogo"
                app:layout_constraintTop_toBottomOf="@id/tvTitle"
                tools:text="Internal server problem. Please try again later" />

        </androidx.constraintlayout.widget.ConstraintLayout>

    </androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>

Hope it helps!

Pedro Antonio
  • 250
  • 1
  • 5
  • 17