Почему два TextView из xml не "сохраняют" одинаковое поле - PullRequest
0 голосов
/ 11 февраля 2020

У меня есть xml файл с 4 TextView. При накачивании xml. Я надуваю xml из разных фрагментов, в некоторых фрагментах я делаю TextView2 видимость до GONE . Проблема в том, что во фрагментах, которые я устанавливаю TextView2 в GONE , пространство между TextView3 и TextView4 меньше чем разрыв между этими двумя TextView , когда TextView2 видимость Видимость (хотя TextView4 начало ограничено TextView3 ). Может кто-нибудь объяснить мне причину такого поведения, а также предложить мне удобное решение?

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:background="@color/backgroundColor">

    <Spinner
        android:id="@+id/spinner"
        android:layout_width="0dp"
        android:layout_height="48dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        android:layout_marginStart="3dp"
        android:layout_marginEnd="3dp"
        android:layout_marginTop="5dp"
        android:dropDownWidth="120dp"
        android:gravity="center"
        android:dropDownVerticalOffset="96dp"
        android:background="@null"
        android:visibility="invisible"/>


    <Button
        android:id="@+id/tempButton"
        android:layout_width="wrap_content"
        android:layout_height="34dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/spinner"
        android:layout_marginTop="8dp"
        tools:text="Button"
        android:textSize="13sp"
        android:visibility="invisible"
        />


    <TextView android:id="@+id/textView1"
        android:layout_width="60dp"
        android:layout_height="13dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/tempButton"
        android:layout_marginTop="22dp"
        android:layout_marginStart="12dp"
        android:textSize="11sp"
        android:textColor="@color/titleTextColor"
        tools:text="TextView1" />


    <TextView android:id="@+id/textView2"
        android:layout_width="100dp"
        android:layout_height="13dp"
        app:layout_constraintStart_toEndOf="@id/textView1"
        app:layout_constraintTop_toBottomOf="@id/tempButton"
        android:layout_marginTop="22dp"
        android:layout_marginStart="6dp"
        android:textSize="11sp"
        android:textColor="@color/titleTextColor"
        android:text="Symbol"
        tools:text="TextView2"/>



    <TextView android:id="@+id/textView3"
        android:layout_width="60dp"
        android:layout_height="13dp"
        app:layout_constraintTop_toBottomOf="@id/tempButton"
        app:layout_constraintStart_toEndOf="@id/textView2"
        android:layout_marginTop="22dp"
        android:layout_marginStart="4dp"
        app:layout_goneMarginStart="65dp"
        android:textSize="11sp"
        android:textColor="@color/titleTextColor"
        tools:text="TextView3" />

    <TextView android:id="@+id/textView4"
        android:layout_width="60dp"
        android:layout_height="13dp"
        app:layout_constraintTop_toBottomOf="@id/tempButton"
        app:layout_constraintStart_toEndOf="@id/textView3"
        android:layout_marginTop="22dp"
        android:layout_marginStart="55dp"
        android:textSize="11sp"
        android:textColor="@color/titleTextColor"
        tools:text="TextView4" />




    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerView"
        android:layout_width="0dp"
        android:layout_height="0dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView1"
        app:layout_constraintBottom_toBottomOf="parent"
        android:layout_marginStart="3dp"
        android:layout_marginEnd="3dp"
        android:layout_marginTop="7dp"
        android:visibility="invisible" />

    <ProgressBar
        android:id="@+id/progressBar"
        android:visibility="visible"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintTop_toBottomOf="@id/textView1"
        app:layout_constraintBottom_toBottomOf="parent" />


</androidx.constraintlayout.widget.ConstraintLayout>

1 Ответ

0 голосов
/ 11 февраля 2020

Ваш textView2 имеет:

android:layout_marginTop="22dp"
android:layout_marginStart="6dp"

, поэтому, когда вы устанавливаете видимость на GONE, эти поля также исчезают. Попробуйте вместо этого INVISIBLE, если хотите сохранить поля!

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...