【发布时间】:2026-02-16 18:55:01
【问题描述】:
你知道我有一个问题,为什么我有这样的“添加”按钮,它实际上就好像它正在离开活动,即使文本“添加数据......”也是错误的,因为这个,我不得不说我对来自 android studio 的所有这一切还是新手,所以任何东西都可以帮助我,我尝试了很多但我无法完全显示按钮,只有你在图像中看到的部分(我尝试使用线性布局)
this is how I would like it to look
我添加xml代码
<?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/ConstraintLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_degradado"
tools:context=".NuevoPacienteActivity">
<androidx.cardview.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="10dp"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="15dp"
app:cardElevation="10dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/ConstraintLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:paddingBottom="16dp"
android:text="@string/agregue_datos_del_paciente"
android:textAlignment="center"
android:textColor="@color/black"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout8"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout8"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout9"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextRutPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_person_icon"
android:drawablePadding="12dp"
android:hint="@string/rutPa"
android:inputType="textPersonName"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout9"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textInputLayout8"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout8"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextNombrePa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_person_icon"
android:drawablePadding="12dp"
android:hint="@string/nombre"
android:inputType="textPersonName"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout10"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="1dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout11"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textInputLayout9"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout9"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextApellidoPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_person_icon"
android:drawablePadding="12dp"
android:hint="@string/apellidos"
android:inputType="textPersonName"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout11"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout12"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout10"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextEmailPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_email_icon"
android:drawablePadding="12dp"
android:hint="@string/emailPa"
android:inputType="textEmailAddress"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout12"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout13"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout11"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextPhonePa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_phone_icon"
android:drawablePadding="12dp"
android:hint="@string/n_mero_de_celularPa"
android:inputType="phone"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout13"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/textInputLayout14"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout12"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextMotivoConsultaPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_phone_icon"
android:drawablePadding="12dp"
android:hint="@string/motivo_de_consulta"
android:inputType="text"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.textfield.TextInputLayout
android:id="@+id/textInputLayout14"
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:fadeScrollbars="false"
android:importantForAutofill="no"
app:errorEnabled="true"
app:layout_constraintBottom_toTopOf="@+id/buttonAgregarPa"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout13"
tools:ignore="TextContrastCheck,TouchTargetSizeCheck">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/editTextDiagnosticoPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:drawableStart="@drawable/custom_phone_icon"
android:drawablePadding="12dp"
android:hint="@string/diagnostico"
android:inputType="text"
android:textColor="@color/black"
android:textSize="14sp"
tools:ignore="TextContrastCheck" />
</com.google.android.material.textfield.TextInputLayout>
<com.google.android.material.button.MaterialButton
android:id="@+id/buttonAgregarPa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:text="@string/agregarPa"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout14"
tools:ignore="TouchTargetSizeCheck" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.cardview.widget.CardView>
</androidx.constraintlayout.widget.ConstraintLayout>
【问题讨论】:
-
给父ConstraintLayout加一些padding,或者给maxHeight = "matchparent"
-
我试过了,但没用
标签: android android-studio android-layout button