【发布时间】:2017-12-09 10:10:27
【问题描述】:
下面的 layout_marginBottom 是否有任何原因不起作用? 但是,如果我在第二个视图上使用 layout_marginTop 效果很好
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ade4ad">
<TextView
android:id="@+id/first"
android:layout_width="90dp"
android:layout_height="40dp"
app:layout_marginBottom="10dp"
android:background="#000"/>
<TextView
android:id="@+id/second"
android:layout_width="90dp"
android:layout_height="40dp"
android:background="#fff"
app:layout_constraintTop_toBottomOf="@+id/first"/>
</android.support.constraint.ConstraintLayout>
【问题讨论】:
-
我添加了完全相同的问题,并通过向您的第一个 textView 添加以下约束来修复它:app:layout_constraintBottomToBottomOf="@+id/second"。然后 marginBottom 运行良好
-
你需要有一个约束才能有一个边距。例如,对于底部边距,底部约束是必须的。其他方面也类似。
-
感谢 shiva,这是正确的答案。
标签: android margin android-constraintlayout