【发布时间】:2020-02-27 17:28:17
【问题描述】:
我有 ConstraintLayout,里面有两个 TextView:
<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="wrap_content">
<TextView
android:id="@+id/first"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/second"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toRightOf="@+id/first"
app:layout_constraintRight_toRightOf="parent"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</androidx.constraintlayout.widget.ConstraintLayout>
我想将第一个放在父容器的左上角,并将第二个放在父容器的右上角。但是两个文本视图都可以包含任意长度的文本。当第一个文本很长时,它会与第二个文本视图重叠。我可以通过在 LinearLayout 中包装两个文本视图来解决这个问题。但这种方式在我看来并不优雅。也许还有另一种方法可以做到这一点?我的意思是 ConstraintLayout 的功能
【问题讨论】:
-
你可以改用相对布局
-
你需要水平链和宽度与
0dp
标签: android android-constraintlayout