Android:切断约束布局

huangapple go评论75阅读模式
英文:

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">

&lt;EditText
    android:id=&quot;@+id/editText&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;48dp&quot;
    android:autofillHints=&quot;&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Title&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

&lt;EditText
    android:id=&quot;@+id/editText3&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;148dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Description&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

&lt;EditText
    android:id=&quot;@+id/editText4&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;104dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:clickable=&quot;true&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Time&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/editText3&quot; /&gt;

&lt;Button
    android:id=&quot;@+id/button_add_new_todo&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginEnd=&quot;32dp&quot;
    android:layout_marginBottom=&quot;32dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:text=&quot;Button&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot; /&gt;

&lt;androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;0dp&quot;
    android:layout_marginStart=&quot;1dp&quot;
    android:layout_marginEnd=&quot;1dp&quot;
    android:layout_marginBottom=&quot;256dp&quot;
    android:adjustViewBounds=&quot;true&quot;
    android:background=&quot;@color/colorAccent&quot;
    android:orientation=&quot;horizontal&quot;
    android:scaleType=&quot;centerInside&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintHorizontal_bias=&quot;0.0&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/editText4&quot;
    app:layout_constraintVertical_bias=&quot;1.0&quot;&gt;

    &lt;ImageButton
        android:id=&quot;@+id/imageButton&quot;
        android:layout_width=&quot;47dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:layout_marginStart=&quot;16dp&quot;
        android:layout_marginTop=&quot;16dp&quot;
        android:layout_marginBottom=&quot;26dp&quot;
        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        app:srcCompat=&quot;@drawable/alarm_clock_1&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

</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&#39;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">

&lt;EditText
    android:id=&quot;@+id/editText&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;48dp&quot;
    android:autofillHints=&quot;&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Title&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

&lt;EditText
    android:id=&quot;@+id/editText3&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;148dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Description&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toTopOf=&quot;parent&quot; /&gt;

&lt;EditText
    android:id=&quot;@+id/editText4&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginTop=&quot;104dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:clickable=&quot;true&quot;
    android:ems=&quot;10&quot;
    android:hint=&quot;Time&quot;
    android:inputType=&quot;textPersonName&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/editText3&quot; /&gt;

&lt;Button
    android:id=&quot;@+id/button_add_new_todo&quot;
    android:layout_width=&quot;wrap_content&quot;
    android:layout_height=&quot;wrap_content&quot;
    android:layout_marginEnd=&quot;32dp&quot;
    android:layout_marginBottom=&quot;32dp&quot;
    android:background=&quot;@drawable/square_round&quot;
    android:text=&quot;Button&quot;
    android:textColor=&quot;@color/cardview_light_background&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot; /&gt;

&lt;androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width=&quot;0dp&quot;
    android:layout_height=&quot;0dp&quot;
    android:layout_marginStart=&quot;1dp&quot;
    android:layout_marginEnd=&quot;1dp&quot;
    android:layout_marginBottom=&quot;256dp&quot;
    android:adjustViewBounds=&quot;true&quot;
    android:background=&quot;@color/colorAccent&quot;
    android:orientation=&quot;horizontal&quot;
    android:scaleType=&quot;centerInside&quot;
    app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
    app:layout_constraintEnd_toEndOf=&quot;parent&quot;
    app:layout_constraintHorizontal_bias=&quot;0.0&quot;
    app:layout_constraintStart_toStartOf=&quot;parent&quot;
    app:layout_constraintTop_toBottomOf=&quot;@+id/editText4&quot;
    app:layout_constraintVertical_bias=&quot;1.0&quot;&gt;

    &lt;ImageButton
        android:id=&quot;@+id/imageButton&quot;
        android:layout_width=&quot;47dp&quot;
        android:layout_height=&quot;50dp&quot;
        android:layout_marginStart=&quot;16dp&quot;
        android:layout_marginTop=&quot;16dp&quot;
        android:layout_marginBottom=&quot;26dp&quot;
        app:layout_constraintBottom_toBottomOf=&quot;parent&quot;
        app:layout_constraintStart_toStartOf=&quot;parent&quot;
        app:layout_constraintTop_toTopOf=&quot;parent&quot;
        app:srcCompat=&quot;@drawable/alarm_clock_1&quot; /&gt;
&lt;/androidx.constraintlayout.widget.ConstraintLayout&gt;

</androidx.constraintlayout.widget.ConstraintLayout>

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/r3sA0.png

</details>


# 答案1
**得分**: 0

似乎在您的嵌套约束布局中有一个不必要的 `android:layout_marginBottom=&quot;256dp&quot;`。

<details>
<summary>英文:</summary>

It seems that you have an unnecessary `android:layout_marginBottom=&quot;256dp&quot;` in your nested constraint layout.

</details>



huangapple
  • 本文由 发表于 2020年8月4日 04:07:45
  • 转载请务必保留本文链接:https://go.coder-hub.com/63236270.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定