У меня есть несколько полей, которые являются необязательными, в зависимости исключительно от выбора пользователя, пользователь может выбрать заполнить только 3, как выбрать заполнить все, и т. Д. c. В зависимости от того, что он выбирает, я «скрываю» кнопки в зависимости от того, что выбрать, и показываю только те, которые были выбраны ранее, например:
Понимают, что когда пользователь выбирает все поля, они правильно распределены по вертикали.
Однако, когда выбрано только несколько полей, происходит следующее:
Поля продолжают выравниваться до степени текста редактирования, который теперь невидим, не «автоматически выравнивать», мне было интересно, возможно ли выравнивание динамически в зависимости от того, что отмечено, это мой xml код:
<?xml version="1.0" encoding="utf-8"?>
<androidx.core.widget.NestedScrollView 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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:layout_gravity="top"
android:scrollbars="vertical">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toStartOf="@+id/botaoOpcao"
app:layout_constraintStart_toStartOf="@+id/botaoOpcao">
<TextView
android:id="@+id/textPeso"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="164dp"
android:layout_marginTop="16dp"
android:gravity="center"
android:text="Peso:"
android:textColor="@android:color/black"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorpesoboi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="38dp"
android:layout_marginBottom="6dp"
android:backgroundTint="@android:color/white"
android:hint="Pressione salvar na Balança ou Digite"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintBottom_toTopOf="@+id/textViewTag"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/receive_peso"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:maxLength="7"
android:textSize="22sp"
android:textStyle="bold" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/textViewTag"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="152dp"
android:layout_marginTop="148dp"
android:text="Tag/ID:"
android:textColor="@android:color/black"
android:textSize="30dp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editortagboi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="38dp"
android:backgroundTint="@android:color/white"
android:hint="Passe o Tag na balança ou Digite"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintStart_toStartOf="@id/textViewTag"
app:layout_constraintTop_toTopOf="@id/textViewTag">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/receive_tag"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textSize="22sp"
android:textStyle="bold" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/delay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:gravity="center"
android:text="Pressione o botão de salvar na balança e aguarde os dados"
android:textAlignment="center"
android:textColor="@color/laranja5"
android:textSize="25dp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textViewTag" />
<ProgressBar
android:id="@+id/progressBarDelay"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:indeterminate="true"
android:indeterminateDuration="2000"
android:max="100"
android:min="0"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/delay" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorloteBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Digite o lote"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/botaoOpcao"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editloteBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:maxLength="2"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editordataBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Data de nascimento"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editorloteBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editdataBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="date"
android:maxLength="10"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editoridadeBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Idade do Bovino"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editordataBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editidadeBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="number"
android:maxLength="3"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editormaeBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Mãe do Bovino"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editoridadeBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editmaeBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textPersonName"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorpaiBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Pai do Bovino"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editormaeBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editpaiBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textPersonName"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editormedBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Medicamentos"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editorpaiBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editmedBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textMultiLine"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorvacinaBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Vacinas"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editormedBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editvacinaBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="text"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorpatologiaBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Patologias"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editorvacinaBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editpatologiaBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="textMultiLine"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/editorchifreBoi"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox.Dense"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@android:color/white"
android:hint="Tipo de chifre"
android:textColorHint="@color/colorPrimary"
app:boxCornerRadiusBottomEnd="18dp"
app:boxCornerRadiusBottomStart="18dp"
app:boxCornerRadiusTopEnd="18dp"
app:boxCornerRadiusTopStart="18dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/editorpatologiaBoi"
tools:layout_editor_absoluteY="293dp">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editchifreBoi"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:inputType="text"
android:textStyle="bold"
tools:layout_editor_absoluteX="-27dp"
tools:layout_editor_absoluteY="265dp" />
</com.google.android.material.textfield.TextInputLayout>
<TextView
android:id="@+id/textGeneroBoi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginEnd="3dp"
android:text="Gênero:"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/radioGpGenero"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editorchifreBoi" />
<RadioGroup
android:id="@+id/radioGpGenero"
style="@style/Widget.AppCompat.CompoundButton.RadioButton"
android:layout_width="0dp"
android:layout_height="26dp"
android:layout_marginEnd="120dp"
android:orientation="horizontal"
app:layout_constraintBottom_toBottomOf="@+id/textGeneroBoi"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/listaOpcaoPat">
<RadioButton
android:id="@+id/botaoradMasculino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="12dp"
android:buttonTint="@color/colorPrimary"
android:checked="true"
android:text="Macho"
android:textColor="@color/azul4"
android:textSize="18sp"
android:textStyle="bold" />
<RadioButton
android:id="@+id/botaoradFeminino"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:buttonTint="@color/colorPrimary"
android:text="Fêmea"
android:textColor="@color/vermelho3"
android:textSize="18sp"
android:textStyle="bold" />
</RadioGroup>
<TextView
android:id="@+id/textRaca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_marginStart="16dp"
android:layout_marginTop="20dp"
android:layout_marginEnd="20dp"
android:text="Raça:"
android:textColor="@android:color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toStartOf="@+id/listaOpcaoPat"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textGeneroBoi" />
<Spinner
android:id="@+id/listaOpcaoRaca"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="36dp"
android:backgroundTint="@color/colorPrimary"
android:gravity="center_horizontal"
android:paddingEnd="5dp"
android:scrollbarSize="51dp"
android:spinnerMode="dropdown"
app:layout_constraintBottom_toBottomOf="@+id/textRaca"
app:layout_constraintEnd_toEndOf="@+id/radioGpGenero" />
<com.google.android.material.button.MaterialButton
android:id="@+id/saveBoi"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_marginEnd="136dp"
android:drawableRight="@drawable/ic_save_black_24dp"
android:drawablePadding="3dp"
android:drawableTint="@color/colorPrimary"
android:text="Salvar"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@+id/botaoOpcao"
app:strokeColor="@color/colorPrimary"
app:strokeWidth="2.5dp" />
<com.google.android.material.button.MaterialButton
android:id="@+id/botaoOpcao"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="240dp"
android:layout_marginTop="16dp"
android:drawableLeft="@drawable/ic_add_black_24dp"
android:drawablePadding="3dp"
android:text="Opções"
android:textColor="@android:color/black"
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.027"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/progressBarDelay" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>
Это код видимости:
dataNasc = view.findViewById(R.id.editdataBoi);
if(getArguments().getBoolean("data_nascimento")){
dataNasc.setVisibility(View.VISIBLE);
}else{
dataNasc.setVisibility(View.GONE);
}
idadeBov = view.findViewById(R.id.editidadeBoi);
if(getArguments().getBoolean("idade_bovino")){
idadeBov.setVisibility(View.VISIBLE);
}else{
idadeBov.setVisibility(View.GONE);
}
maeBov = view.findViewById(R.id.editmaeBoi);
if(getArguments().getBoolean("mae_bovino")){
maeBov.setVisibility(View.VISIBLE);
}else{
maeBov.setVisibility(View.GONE);
}
paiBov = view.findViewById(R.id.editpaiBoi);
if(getArguments().getBoolean("pai_bovino")){
paiBov.setVisibility(View.VISIBLE);
}else{
paiBov.setVisibility(View.GONE);
}
medBov = view.findViewById(R.id.editmedBoi);
if(getArguments().getBoolean("med_bovino")){
medBov.setVisibility(View.VISIBLE);
}else{
medBov.setVisibility(View.GONE);
}
vacinaBov = view.findViewById(R.id.editvacinaBoi);
if(getArguments().getBoolean("vacina_bovino")){
vacinaBov.setVisibility(View.VISIBLE);
}else{
vacinaBov.setVisibility(View.GONE);
}
patologiaBov = view.findViewById(R.id.editpatologiaBoi);
if(getArguments().getBoolean("patologia_bovino")){
patologiaBov.setVisibility(View.VISIBLE);
}else{
patologiaBov.setVisibility(View.GONE);
}
chifreBov = view.findViewById(R.id.editchifreBoi);
if(getArguments().getBoolean("tipoChifreBovino")){
chifreBov.setVisibility(View.VISIBLE);
}else{
chifreBov.setVisibility(View.GONE);
}