Home > other >  dashed line view does not show when the height is " wrap content " in XML
dashed line view does not show when the height is " wrap content " in XML

Time:11-01

I'm trying to create dashed line view but when it takes the height as match parent or wrap content it does not show, it only show when it takes a fixed height but that don't work for my list, and I need to make it match parent

here is the line layout :

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
    android:bottom="-1dp"
    android:left="-1dp"
    android:right="-1dp"
    android:top="0dp">
    <rotate
        android:fromDegrees="90"
        android:toDegrees="90">
        <shape android:shape="line">
            <stroke
                android:width="1dp"
                android:color="#E7EBEE"
                android:dashWidth="3dp"
                android:dashGap="3dp" />

            <solid android:color="@android:color/white" />


        </shape>
    </rotate>
</item>

and i set it as a background to view tag in the XML Like this :

<View
    android:id="@ id/view"
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:background="@drawable/dotted_line"
    android:layerType="software"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="@ id/circleShape"
    app:layout_constraintStart_toStartOf="@ id/circleShape"
    app:layout_constraintTop_toBottomOf="@ id/circleShape" />

CodePudding user response:

wrap_content won't work in your case since your view doesn't really have any content, so the height would be 0.

what you can do is to set the height to 0dp for the dashed line view. since you have a top and bottom constraints, which will make it take the entire space between the top constraint and the bottom constraint.

  • Related