Связывание двух TextView по вертикали

Существует RelativeLayout с вложенным LinearLayout, который содержит два TextViews, расположенных горизонтально друг относительно друга. Это DiscountAmount и AmountWithDiscount.

Связывание двух TextView по вертикали

Мне нужно, чтобы DiscountAmount и AmountWithDiscount всегда были на одном уровне по вертикали, для этого я поместил свойство android в LinearLayout: android:layout_below = "@ + id / textViewRowQuantity". Но если Name слишком длинный и занимает три строки, то он перейдет к DiscountAmount. Если Name занимает не более 2-х строк, то все хорошо.

Подскажите, пожалуйста, как решить эту проблему?

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/relativeLayoutSaleListRow"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_marginBottom = "2dp"
android:orientation = "horizontal"
android:padding = "5dp" >

<ImageView
    android:id = "@+id/imageViewRemoveRowSale"
    android:layout_width = "@dimen/size_30px"
    android:layout_height = "@dimen/size_30px"
    android:layout_alignParentLeft = "true"
    android:layout_marginRight = "10dp"
    android:layout_marginTop = "10dp"
    android:src = "@drawable/ic_action_remove"/>

<RelativeLayout
    android:id = "@+id/relativeLayoutIncQuantity"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_marginRight = "10dp"
    android:layout_toRightOf = "@+id/imageViewRemoveRowSale"
    android:layout_toLeftOf = "@+id/imageViewEditRowSale"
    android:orientation = "horizontal">


<TextView
    android:id = "@+id/textViewRowPrice"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_alignParentRight = "true"
    android:layout_marginRight = "5dp"
    android:text = "TextView" />

<TextView
    android:id = "@+id/textViewRowQuantity"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_below = "@+id/textViewRowPrice"
    android:layout_alignParentRight = "true"
    android:layout_marginRight = "5dp"
    android:text = "TextView" />


<TextView
    android:id = "@+id/textViewRowName"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_alignParentLeft = "true"
    android:layout_toLeftOf = "@+id/textViewRowPrice"
    android:text = "TextView" />



    <LinearLayout
        android:id = "@+id/layoutDiscount"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_below = "@+id/textViewRowQuantity"
        android:orientation = "horizontal">

        <TextView
            android:id = "@+id/textViewRowDiscountAmount"
            android:layout_width = "wrap_content"
            android:layout_weight = "1"
            android:layout_height = "wrap_content"
            android:layout_marginRight = "5dp"
            android:text = "TextView" />

        <TextView
        android:id = "@+id/textViewRowAmountWithDiscount"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
            android:gravity = "right"
            android:layout_weight = "1"
        android:layout_marginRight = "5dp"
        android:text = "TextView" />
  </LinearLayout>

    </RelativeLayout>

<ImageView
    android:id = "@+id/imageViewEditRowSale"
    android:layout_width = "@dimen/size_45px"
    android:layout_height = "@dimen/size_45px"
    android:layout_marginTop = "5dp"
    android:layout_alignParentRight = "true"
    android:src = "@drawable/ic_action_edit" />

Добавить результат: Связывание двух TextView по вертикали

Реализовано через ConstraintLayout. Спасибо всем.

0
0
84
5

Ответы 5

Вы можете ограничить количество строк в TextView до 2, добавив следующие строки:

android:ellipsize = "end"
android:lines = "2"

Конец многоточия конец означает, что если текст такой длинный, он будет заменен тремя точками ...

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

 <?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
    android:id = "@+id/relativeLayoutSaleListRow"
    android:layout_width = "match_parent"
    android:layout_height = "match_parent"
    android:layout_marginBottom = "2dp"
    android:orientation = "horizontal"
    android:padding = "5dp" >

    <ImageView
        android:id = "@+id/imageViewRemoveRowSale"
        android:layout_width = "@dimen/size_30px"
        android:layout_height = "@dimen/size_30px"
        android:layout_alignParentLeft = "true"
        android:layout_marginRight = "10dp"
        android:layout_marginTop = "10dp"
        android:src = "@drawable/ic_action_remove"/>

    <RelativeLayout
        android:id = "@+id/relativeLayoutIncQuantity"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_marginRight = "10dp"
        android:layout_toRightOf = "@+id/imageViewRemoveRowSale"
        android:layout_toLeftOf = "@+id/imageViewEditRowSale"
        android:orientation = "horizontal">


        <TextView
            android:id = "@+id/textViewRowPrice"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_alignParentRight = "true"
            android:layout_marginRight = "5dp"
            android:text = "TextView" />

        <TextView
            android:id = "@+id/textViewRowQuantity"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_below = "@+id/textViewRowPrice"
            android:layout_alignParentRight = "true"
            android:layout_marginRight = "5dp"
            android:text = "TextView" />


        <TextView
            android:id = "@+id/textViewRowName"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:layout_alignParentLeft = "true"
            android:layout_toLeftOf = "@+id/textViewRowPrice"
            android:text = "text"
            android:minLines = "2"/>



        <LinearLayout
            android:id = "@+id/layoutDiscount"
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_below = "@+id/textViewRowName"
            android:orientation = "horizontal">

            <TextView
                android:id = "@+id/textViewRowDiscountAmount"
                android:layout_width = "wrap_content"
                android:layout_weight = "1"
                android:layout_height = "wrap_content"
                android:layout_marginRight = "5dp"
                android:text = "TextView" />

            <TextView
                android:id = "@+id/textViewRowAmountWithDiscount"
                android:layout_width = "wrap_content"
                android:layout_height = "wrap_content"
                android:gravity = "right"
                android:layout_weight = "1"
                android:layout_marginRight = "5dp"
                android:text = "TextView" />
        </LinearLayout>

    </RelativeLayout>


    <ImageView
        android:id = "@+id/imageViewEditRowSale"
        android:layout_width = "@dimen/size_45px"
        android:layout_height = "@dimen/size_45px"
        android:layout_marginTop = "5dp"
        android:layout_alignParentRight = "true"
        android:src = "@drawable/ic_action_edit" />

</RelativeLayout>

Надеюсь это поможет

если вы хотите показать, что AmountWithDiscount ниже для скидки, измените ориентацию макета лайнера, как показано ниже.

android:orientation = "vertical"

В relativeLayoutIncQuantity? Ничего не изменилось

EfremovAV 21.03.2018 10:14

я не понимаю ваше требование. поэтому, пожалуйста, предоставьте изображение для отображения всего текста.

Android Team 21.03.2018 10:16

Я добавил картинку к своему вопросу, пожалуйста, посмотрите

EfremovAV 21.03.2018 10:24

Вы можете попробовать этот код ниже

<?xml version = "1.0" encoding = "utf-8"?>
<RelativeLayout xmlns:android = "http://schemas.android.com/apk/res/android"
android:id = "@+id/relativeLayoutSaleListRow"
android:layout_width = "match_parent"
android:layout_height = "match_parent"
android:layout_marginBottom = "2dp"
android:orientation = "horizontal"
android:padding = "5dp" >

<ImageView
    android:id = "@+id/imageViewRemoveRowSale"
    android:layout_width = "@dimen/size_30px"
    android:layout_height = "@dimen/size_30px"
    android:layout_alignParentLeft = "true"
    android:layout_marginRight = "10dp"
    android:layout_marginTop = "10dp"
    android:src = "@drawable/ic_action_remove"/>

<RelativeLayout
    android:id = "@+id/relativeLayoutIncQuantity"
    android:layout_width = "wrap_content"
    android:layout_height = "wrap_content"
    android:layout_marginRight = "10dp"
    android:layout_toRightOf = "@+id/imageViewRemoveRowSale"
    android:layout_toLeftOf = "@+id/imageViewEditRowSale"
    android:orientation = "horizontal">

    <RelativeLayout
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:id = "@+id/rr_layout">

    <TextView
        android:id = "@+id/textViewRowPrice"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_alignParentRight = "true"
        android:layout_marginRight = "5dp"
        android:text = "TextView" />

    <TextView
        android:id = "@+id/textViewRowQuantity"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_below = "@+id/textViewRowPrice"
        android:layout_alignParentRight = "true"
        android:layout_marginRight = "5dp"
        android:text = "TextView" />


    <TextView
        android:id = "@+id/textViewRowName"
        android:layout_width = "wrap_content"
        android:layout_height = "wrap_content"
        android:layout_alignParentLeft = "true"
        android:layout_toLeftOf = "@+id/textViewRowPrice"
        android:text = "TextView" />

    </RelativeLayout>

    <LinearLayout
        android:id = "@+id/layoutDiscount"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_below = "@+id/rr_layout"
        android:orientation = "horizontal">

        <TextView
            android:id = "@+id/textViewRowDiscountAmount"
            android:layout_width = "wrap_content"
            android:layout_weight = "1"
            android:layout_height = "wrap_content"
            android:layout_marginRight = "5dp"
            android:text = "TextView" />

        <TextView
            android:id = "@+id/textViewRowAmountWithDiscount"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:gravity = "right"
            android:layout_weight = "1"
            android:layout_marginRight = "5dp"
            android:text = "TextView" />
    </LinearLayout>

</RelativeLayout>

<ImageView
    android:id = "@+id/imageViewEditRowSale"
    android:layout_width = "@dimen/size_45px"
    android:layout_height = "@dimen/size_45px"
    android:layout_marginTop = "5dp"
    android:layout_alignParentRight = "true"
    android:src = "@drawable/ic_action_edit" /></RelativeLayout>

внести некоторые изменения в линейную компоновку ..

        <LinearLayout
        android:id = "@+id/layoutDiscount"
        android:layout_width = "match_parent"
        android:layout_height = "wrap_content"
        android:layout_below = "@+id/textViewRowQuantity"
        android:orientation = "horizontal"
        android:weightSum = "1"
        >
        <LinearLayout
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_weight = "0.3">
        <TextView
            android:id = "@+id/textViewRowDiscountAmount"
            android:layout_width = "wrap_content"
            android:layout_weight = "1"
            android:layout_height = "wrap_content"
            android:layout_marginRight = "5dp"
            android:singleLine = "true"
            android:text = "TextViewsdfsdfdsgfd" />
        </LinearLayout>
        <LinearLayout
            android:layout_width = "match_parent"
            android:layout_height = "wrap_content"
            android:layout_weight = "0.7">
        <TextView
            android:id = "@+id/textViewRowAmountWithDiscount"
            android:layout_width = "wrap_content"
            android:layout_height = "wrap_content"
            android:gravity = "right"
            android:layout_marginLeft = "10dp"
            android:layout_weight = "1"
            android:singleLine = "true"
            android:layout_marginRight = "5dp"
            android:text = "textview" />
        </LinearLayout>
    </LinearLayout>

Другие вопросы по теме