首页 > 解决方案 > ConstraintLayout 奇怪的约束线

问题描述

我正在使用约束布局,据我了解,它会使 UI 在不同的屏幕尺寸上看起来相似。问题是我无法将约束线从日历视图拖到 textView

因此,我创建了我需要使用的约束线

app:layout_constraintBottom_toTopOf="@+id/appfortday"

图片:https ://imgur.com/a/xG1eCH6

它创造了这条奇怪的摆动线而不是正常的之字形线。这些行之间有什么区别?它会表现得像一条正常的约束线吗?

这是我的 xml 的一部分:

<CalendarView
    android:id="@+id/calendarView"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_below="@+id/textcalender"
    android:layout_marginTop="56dp"
    app:layout_constraintBottom_toTopOf="@+id/appfortday"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.0"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/textcalender" />

<TextView
    android:id="@+id/appfortday"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="10dp"
    android:text="Appointments for today"
    android:textSize="15dp"
    app:layout_constraintBottom_toTopOf="@+id/feelingsrec"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintHorizontal_bias="0.2"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/calendarView"
    app:layout_constraintVertical_bias="0.49" />

我想知道这些行之间的区别,以及它是否会影响我的 UI 在不同屏幕尺寸上的显示方式。谢谢

标签: javaandroidandroid-studioandroid-constraintlayout

解决方案


“摇摆不定”的线表明,两个视图具有指向彼此的约束。

calendarView对顶部有约束,appfortday反之亦然。

还行吧。如果您的视图具有相互指向的约束,您可以通过添加链样式来更改它们的对齐方式。


推荐阅读