Android 为表示布局中的线的视图创建动态背景

Android 为表示布局中的线的视图创建动态背景,android,android-layout,background,Android,Android Layout,Background,我想要的结果是这样的- 如您所见,黑线正被拉伸到其上方文本的正下方,这意味着它需要动态调整 我目前的布局如下: 看起来是这样的- 我目前在整个视图中使用黑色后所需的纯色,因此我需要一个背景,该背景的黑色百分比与所需的相同,其余部分为我的当前颜色值 如何使背景成为所需的结果 试试这个: <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmln

我想要的结果是这样的-

如您所见,黑线正被拉伸到其上方文本的正下方,这意味着它需要动态调整

我目前的布局如下:


看起来是这样的-

我目前在整个视图中使用黑色后所需的纯色,因此我需要一个背景,该背景的黑色百分比与所需的相同,其余部分为我的当前颜色值

如何使背景成为所需的结果

试试这个:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="16dp"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <TextView
        android:id="@+id/tvNumber"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:background="#000000"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        android:gravity="center"
        android:text="5"
        android:textColor="#ffffff"
        android:textStyle="bold" />


    <TextView
        android:id="@+id/tvContent"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="@id/tvNumber"
        app:layout_constraintBottom_toBottomOf="@id/tvNumber"
        app:layout_constraintLeft_toRightOf="@+id/tvNumber"
        android:paddingLeft="8dp"
        android:text="Payment Information"
        android:textColor="#000000"
        android:textStyle="bold" />

    <View
        android:layout_width="0dp"
        android:layout_height="1dp"
        app:layout_constraintTop_toBottomOf="@+id/tvNumber"
        app:layout_constraintLeft_toLeftOf="@+id/tvNumber"
        app:layout_constraintRight_toRightOf="@+id/tvContent"
        android:layout_marginTop="16dp"
        android:background="#000000"
        />

    <View
        android:layout_width="match_parent"
        android:layout_height="0.5dp"
        app:layout_constraintTop_toBottomOf="@+id/tvNumber"
        android:layout_marginTop="16dp"
        android:background="#CCC6D6"
        android:visibility="visible"
        />



</androidx.constraintlayout.widget.ConstraintLayout>