考虑一个琐碎的 ConstraintLayout ,其中垂直线 GuideLine 占20%,在不可见线的左侧留有一个难看的垂直竖线(请参见XML)。
我可以按照tynn's example使用 ConstraintSet.setGuidelinePercent()以编程方式操作百分位数,但我需要更动态的实现(例如:可拖动的GuideLine或Barrier )。
必须比将拖动侦听器附加到垂直栏并使用 setGuidelinePercent()更好的方法?
ConstraintLayout 不会提供本机解决方案似乎令人难以理解-也许我只是找不到它?
示例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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/leftTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#AAA"
android:text="LEFT: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/verticalBar"
/>
<View android:id="@+id/verticalBar"
android:layout_width="8dp"
android:layout_height="match_parent"
android:background="#000000"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintEnd_toStartOf="@id/guideLine" />
<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideLine"
android:layout_width="1dp"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent=".20" />
<TextView
android:id="@+id/rightTV"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_margin="8dp"
android:background="#DDD"
android:text="RIGHT: abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@+id/guideLine"
app:layout_constraintEnd_toEndOf="parent"
/>
</androidx.constraintlayout.widget.ConstraintLayout>