создание динамического c фона для представления, представляющего линию в макете - PullRequest
0 голосов
/ 30 января 2020

Нужный результат, который я хочу, выглядит следующим образом -

enter image description here

, где, как вы можете видеть, черная линия растягивается точно под текстом выше это означает, что он должен быть динамически настраиваемым

Текущий макет у меня следующий -

 <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout_1"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_billing_address"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_billing_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout_2"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_shipping_address"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_shipping_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout_3"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_shipping_method"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_payment_method_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout_4"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_payment_method"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_payment_information_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout_5"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_payment_information"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_confirm_order_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="25dp"
                    android:layout_height="25dp"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:layout_marginTop="@dimen/marketplace_15dp"
                    android:background="@color/color_black"
                    android:gravity="center"
                    android:text="@string/activity_checkout__6"
                    android:textColor="@color/white"
                    android:textStyle="bold" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="bottom"
                    android:layout_marginStart="@dimen/marketplace_14dp"
                    android:text="@string/activity_checkout_confirm_information"
                    android:textColor="@color/color_black"
                    android:textSize="18sp"
                    android:textStyle="bold" />

            </LinearLayout>

            <View
                android:id="@+id/activity_checkout_confirm_information_view"
                android:layout_width="match_parent"
                android:layout_height="1dp"
                android:layout_marginStart="@dimen/marketplace_14dp"
                android:layout_marginTop="@dimen/marketplace_15dp"
                android:layout_marginEnd="@dimen/marketplace_14dp"
                android:background="#DEE2E6" />


        </LinearLayout>

, который выглядит так -

enter image description here

В настоящее время я использую необходимый solid цвет после черного для всего просмотра, поэтому мне нужен фон, который имеет столько же черного процента, сколько необходимо, а остальное текущее значение цвета, которое у меня есть .

Как сделать фон желаемыми результатами?

1 Ответ

0 голосов
/ 30 января 2020

Попробуйте это:

<?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>
...