#android #android-constraintlayout
Вопрос:
Ниже приведен макет ограничения с барьером, но барьер определяется включением повторяющегося текста, но wrap_content
текстовых представлений, которые устанавливаются invisible
только для вычисления размера самой большой метки. При расположении барьера фактическая таблица легко создается путем ограничения конца представлений меток барьером:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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:id="@ id/root"
android:layout_height="match_parent"
android:layout_width="match_parent"
tools:context=".ui.septic.SepticResultAddedFragment"
>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/date_time_for_barrier"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/date_time_label"
android:visibility="invisible"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/click_counter_for_barrier"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/click_counter_label"
android:visibility="invisible"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/runtime_for_barrier"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:visibility="invisible"
android:text="@string/runtime_label"
/>
<androidx.constraintlayout.widget.Barrier
android:id="@ id/label_value_barrier"
android:layout_height="match_parent"
android:layout_width="wrap_content"
app:barrierDirection="right"
app:constraint_referenced_ids="date_time_for_barrier,click_counter_for_barrier,runtime_for_barrier"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/sheet_path_label"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Destination Sheet Path"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/sheet_path"
style="@style/MyTextViewValue"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@id/sheet_path_label"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:textSize="18dp"
tools:text="PathA / PathB / Name"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/date_time_label"
style="@style/MyTextViewLabel"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_constraintEnd_toStartOf="@id/label_value_barrier"
app:layout_constraintTop_toTopOf="@ id/date_time"
app:layout_constraintBottom_toBottomOf="@ id/date_time"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/date_time_label"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/date_time"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@ id/sheet_path"
app:layout_constraintStart_toEndOf="@ id/date_time_label"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="textEnd"
android:textSize="18dp"
tools:text="2021/07/13 10:15"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/clicks_label"
style="@style/MyTextViewLabel"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_constraintEnd_toStartOf="@id/label_value_barrier"
app:layout_constraintTop_toTopOf="@ id/clicks"
app:layout_constraintBottom_toBottomOf="@ id/clicks"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/click_counter_label"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/clicks"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@ id/date_time"
app:layout_constraintStart_toEndOf="@ id/clicks_label"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="textEnd"
android:textSize="18dp"
tools:text="12345"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/runtime_label"
style="@style/MyTextViewLabel"
android:layout_height="0dp"
android:layout_width="0dp"
app:layout_constraintEnd_toStartOf="@id/label_value_barrier"
app:layout_constraintTop_toTopOf="@ id/runtime"
app:layout_constraintBottom_toBottomOf="@ id/runtime"
app:layout_constraintStart_toStartOf="parent"
android:text="@string/runtime_label"
/>
<com.google.android.material.textview.MaterialTextView
android:id="@ id/runtime"
style="@style/MyTextViewLabel"
android:layout_height="wrap_content"
android:layout_width="0dp"
app:layout_constraintTop_toBottomOf="@ id/clicks"
app:layout_constraintStart_toEndOf="@ id/runtime_label"
app:layout_constraintEnd_toEndOf="parent"
android:textAlignment="textEnd"
android:textSize="18dp"
tools:text="12345.67"
/>
<com.google.android.material.button.MaterialButton
android:id="@ id/show_button"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:text="Show Sheet"
/>
</androidx.constraintlayout.widget.ConstraintLayout>
Есть ли лучший способ избежать дополнительных представлений текста надписи?