英文:
Android: Cut off constraint layout
问题
添加一个约束布局到另一个约束布局中时,内部布局会被裁剪。
我已经尝试过更改视图的约束顶部,但没有改变任何东西。有人知道为什么会发生这种情况吗?
我还尝试了不同的布局(青色的是罪魁祸首),它们都产生了相同的效果。
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cyberpunk_background"
tools:context=".Todo_create">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:autofillHints=""
android:background="@drawable/square_round"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="148dp"
android:background="@drawable/square_round"
android:ems="10"
android:hint="Description"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="104dp"
android:background="@drawable/square_round"
android:clickable="true"
android:ems="10"
android:hint="Time"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />
<Button
android:id="@+id/button_add_new_todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="@drawable/square_round"
android:text="Button"
android:textColor="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="256dp"
android:adjustViewBounds="true"
android:background="@color/colorAccent"
android:orientation="horizontal"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText4"
app:layout_constraintVertical_bias="1.0">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="47dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="26dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/alarm_clock_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
<details>
<summary>英文:</summary>
When adding a constraint layout within another constraint layout the inner one gets cut off.
I already tried changing the constraint top of view but that didn't change anything. Anyone knows why this is happening?
I also tried it out with different layouts ( the cyan one is the culprit ) which all had the same effect.
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cyberpunk_background"
tools:context=".Todo_create">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="48dp"
android:autofillHints=""
android:background="@drawable/square_round"
android:ems="10"
android:hint="Title"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="148dp"
android:background="@drawable/square_round"
android:ems="10"
android:hint="Description"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<EditText
android:id="@+id/editText4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="104dp"
android:background="@drawable/square_round"
android:clickable="true"
android:ems="10"
android:hint="Time"
android:inputType="textPersonName"
android:textColor="@color/cardview_light_background"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText3" />
<Button
android:id="@+id/button_add_new_todo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="32dp"
android:layout_marginBottom="32dp"
android:background="@drawable/square_round"
android:text="Button"
android:textColor="@color/cardview_light_background"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="1dp"
android:layout_marginEnd="1dp"
android:layout_marginBottom="256dp"
android:adjustViewBounds="true"
android:background="@color/colorAccent"
android:orientation="horizontal"
android:scaleType="centerInside"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText4"
app:layout_constraintVertical_bias="1.0">
<ImageButton
android:id="@+id/imageButton"
android:layout_width="47dp"
android:layout_height="50dp"
android:layout_marginStart="16dp"
android:layout_marginTop="16dp"
android:layout_marginBottom="26dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:srcCompat="@drawable/alarm_clock_1" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
[![enter image description here][1]][1]
[1]: https://i.stack.imgur.com/r3sA0.png
</details>
# 答案1
**得分**: 0
似乎在您的嵌套约束布局中有一个不必要的 `android:layout_marginBottom="256dp"`。
<details>
<summary>英文:</summary>
It seems that you have an unnecessary `android:layout_marginBottom="256dp"` in your nested constraint layout.
</details>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论