Разделенный RelativeLayout оставил RelativeLayout перекрывающимся правом RelativeLayout - PullRequest
0 голосов
/ 28 января 2019

Примечание: это может показаться повторяющимся вопросом, однако я не нашел ни одного, чтобы ответить на мой вопрос / предоставить решение.

У меня есть макет, который я хотел бы, чтобы был разработан следующим образом:

enter image description here

Это то, что я пытался до сих пор:

Текущий дизайн макета:

enter image description here

Соответствующий ( попытки ) XML-макет находится ниже ( спроблема ):

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <RelativeLayout
        android:id="@+id/layout_price"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:layout_toEndOf="@id/layout_details">

        <TextView
            android:id="@+id/subscriptionCost"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentEnd="true"
            android:text="$ 0.00"
            android:textAlignment="textEnd"
            android:textSize="24sp" />

        <TextView
            android:id="@+id/currency"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/subscriptionCost"
            android:layout_alignParentEnd="true"
            android:text="(USD)"
            android:textAlignment="textEnd"
            android:textSize="16sp"
            android:textStyle="italic" />
    </RelativeLayout>


    <RelativeLayout
        android:id="@+id/layout_details"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true">

        <TextView
            android:id="@+id/subscriptionDuration"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentStart="true"
            android:text="2 Year Subscription"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textSize="24sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/subscriptionMessage"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@id/subscriptionDuration"
            android:layout_alignParentStart="true"
            android:text="Oon until Jaunarasdasddasdasd asd asdasdda sdasd asda sd as da sd as da sd a sd as d as d as d asdasdasday 2020"
            android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
            android:textSize="16sp"
            android:textStyle="italic" />
    </RelativeLayout>

</RelativeLayout>

Я думаю, что компоновка, которую я пытаюсь достичь, очевидна, но я все же объясню.

Макет должен предоставитьобзор подписок, предлагаемых в моем приложении.

  • Длительность подписки в левом верхнем углу, с дальнейшими подробностями (которые могут быть многоуровневыми) ниже длительности.

  • Цена подписки в правом верхнем углу и ниже валюты, в которой указана цена.

Проблема

У меня есть 2 RelativeLayout s как левый и правый макеты.Левый макет должен иметь возможность масштабирования в соответствии с размером экрана, в то время как правый макет должен оставаться как wrap_content ширина.

Имея текущее правое RelativeLayout и дочерние как wrap_content, кажется, что левый RelativeLayoutпросто перекрывает и заставляет правильное расположение ниже, даже если установлены android:layout_alignParentTop="true" и android:layout_alignParentEnd="true".

Я не уверен, что является причиной проблемы, но любой совет будет оценен.

Ответы [ 2 ]

0 голосов
/ 28 января 2019

Привет после некоторых проверок, я бы посоветовал вам использовать ConstraintLayout: здесь полный код, который соответствует вашим требованиям

<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:layout_width="match_parent"
  android:layout_height="wrap_content">


  <TextView
    android:id="@+id/subscriptionDuration"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentStart="true"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:text="2 Year Subscription"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
    android:textSize="24sp"
    android:textStyle="bold"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

  <TextView

    android:id="@+id/subscriptionMessage"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_below="@id/subscriptionDuration"
    android:layout_alignParentStart="true"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:text="Oon until Jaunarasdasddasdasd asd asdasdda sdasd asda sd as da sd as da sd a sd as d as d as d asdasdasday 2020"
    android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
    android:textSize="16sp"
    android:textStyle="italic"
    app:layout_constraintEnd_toStartOf="@+id/currency"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/subscriptionDuration" />


  <TextView
    android:id="@+id/subscriptionCost"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_marginEnd="8dp"
    android:text="$ 0.00"
    android:textAlignment="textEnd"
    android:textSize="24sp"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toTopOf="@+id/subscriptionDuration" />

  <TextView
    android:id="@+id/currency"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@id/subscriptionCost"
    android:layout_alignParentEnd="true"
    android:layout_marginTop="8dp"
    android:layout_marginEnd="8dp"
    android:text="(USD)"
    android:textAlignment="textEnd"
    android:textSize="16sp"
    android:textStyle="italic"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/subscriptionCost" />

</android.support.constraint.ConstraintLayout>
0 голосов
/ 28 января 2019

Нет необходимости использовать Nested RelativeLayout для этого

Вы можете использовать один RelativeLayout

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">


    <TextView
        android:id="@+id/subscriptionDuration"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_toStartOf="@id/subscriptionCost"
        android:text="2 Year Subscription"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:textSize="24sp"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/subscriptionCost"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:text="$ 0.00"
        android:textAlignment="textEnd"
        android:textSize="24sp" />


    <TextView
        android:id="@+id/subscriptionMessage"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/subscriptionDuration"
        android:layout_alignParentStart="true"
        android:layout_toStartOf="@id/currency"
        android:text="Oon until Jaunarasdasddasdasd asd asdasdda sdasd asda sd as da sd as da sd a sd as d as d as d asdasdasday 2020"
        android:textAppearance="@style/Base.TextAppearance.AppCompat.Medium"
        android:textSize="16sp"
        android:textStyle="italic" />


    <TextView
        android:id="@+id/currency"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@id/subscriptionCost"
        android:layout_alignParentEnd="true"
        android:text="(USD)"
        android:textAlignment="textEnd"
        android:textSize="16sp"
        android:textStyle="italic" />

</RelativeLayout>

OUTPUT

enter image description here

...