Android TextViews перекрываются - PullRequest
       19

Android TextViews перекрываются

0 голосов
/ 31 августа 2018

У меня есть RelativeLayout с несколькими TextViews с динамическим содержимым, которые в некоторых случаях перекрываются: Overlappping TextViews

Первый пример - проблемный, два других верны. Предпочтительным решением для первого будет разрыв строки для даты. Но я не смог решить эту проблему и в то же время сохранить два других примера в 2 строки для 3 TextViews. (Поскольку текст является динамическим, все 3 примера должны иметь одинаковый исходный код Xml)

Я сделал пример Xml со статическим содержимым для его проверки в редакторе дизайна:

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

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="5dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="7dp">

    <ImageView
        android:id="@+id/tl_team_image"
        android:layout_width="65dp"
        android:layout_height="70dp"
        android:scaleType="fitCenter"/>

    <TextView
        android:id="@+id/tl_team_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image"
        android:text="Lorem ipsum dolor sit amet consectetur"
        android:textSize="60sp"/>

    <TextView
        android:id="@+id/tl_location_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image"
        android:text="Location Number 1"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_place_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_location_view"
        android:gravity="right"
        android:text="Some Very Longplace"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_date_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_location_view"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image"
        android:paddingBottom="2dp"
        android:text="Tomorrow (August 31, 4 p.m.)"
        android:textSize="50sp"/>
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="5dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="7dp">

    <ImageView
        android:id="@+id/tl_team_image2"
        android:layout_width="65dp"
        android:layout_height="70dp"
        android:scaleType="fitCenter"/>

    <TextView
        android:id="@+id/tl_team_view2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image2"
        android:text="Lorem ipsum dolor sit amet consectetur"
        android:textSize="60sp"/>

    <TextView
        android:id="@+id/tl_location_view2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view2"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image2"
        android:text="Location Number 1"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_place_view2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view2"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_location_view2"
        android:gravity="right"
        android:text="A Short Place"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_date_view2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_location_view2"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image2"
        android:paddingBottom="2dp"
        android:text="Tomorrow (August 31, 4 p.m.)"
        android:textSize="50sp"/>
</RelativeLayout>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:paddingBottom="5dp"
                android:paddingLeft="10dp"
                android:paddingRight="10dp"
                android:paddingTop="7dp">

    <ImageView
        android:id="@+id/tl_team_image3"
        android:layout_width="65dp"
        android:layout_height="70dp"
        android:scaleType="fitCenter"/>

    <TextView
        android:id="@+id/tl_team_view3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image3"
        android:text="Lorem ipsum dolor sit amet consectetur"
        android:textSize="60sp"/>

    <TextView
        android:id="@+id/tl_location_view3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view3"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image3"
        android:text="Location Number 1"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_place_view3"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_team_view3"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_location_view3"
        android:gravity="right"
        android:text="Some Very Longplace"
        android:textSize="50sp"/>

    <TextView
        android:id="@+id/tl_date_view3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/tl_location_view3"
        android:layout_marginLeft="10dp"
        android:layout_toRightOf="@+id/tl_team_image3"
        android:paddingBottom="2dp"
        android:text="September 21, 4 p.m."
        android:textSize="50sp"/>
</RelativeLayout>

1 Ответ

0 голосов
/ 31 августа 2018

Проверьте свой третий TextView. Он должен быть размещен ниже секунда textview, в то время как в настоящее время он находится ниже first textview и, следовательно, перекрывается, и то же самое относится к вашим 4th textview

<ImageView
    android:id="@+id/tl_team_image"
    android:layout_width="65dp"
    android:layout_height="70dp"
    android:scaleType="fitCenter"/>

<TextView
    android:id="@+id/tl_team_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/tl_team_image"
    android:text="Lorem ipsum dolor sit amet consectetur"
    android:textSize="60sp"/>

<TextView
    android:id="@+id/tl_location_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tl_team_view"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/tl_team_image"
    android:text="Location Number 1"
    android:textSize="50sp"/>

<TextView
    android:id="@+id/tl_place_view"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tl_location_view"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/tl_location_view"
    android:gravity="right"
    android:text="Some Very Longplace"
    android:textSize="50sp"/>

<TextView
    android:id="@+id/tl_date_view"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/tl_place_view"
    android:layout_marginLeft="10dp"
    android:layout_toRightOf="@+id/tl_team_image"
    android:paddingBottom="2dp"
    android:text="Tomorrow (August 31, 4 p.m.)"
    android:textSize="50sp"/>

...