我遇到约束布局问题,其中一个文本视图中到达第二行的文本不会向下推被限制在其下方的另一个文本视图,直到该行的中间。
我用三个文本视图构建了一个简单的布局。第一个文本视图位于左侧并具有设定的宽度。第二个位于它的右侧,位于它与其父级之间。第三个位于第二个下方,第一个左侧。
I want it to look like:
However if I remove the text "Not Overlapping." I get:
The point at which it changes (The "O" in "Not Overlapping")appears to be when the length of the text fills two lines when the first Text View is not there:
那么如何更改此布局,以便即使我在屏幕左侧有一个文本视图,它也会在文本视图 3 到达两行时将其向下推?而不是将其推到第二行的一半。
My XML:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.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="wrap_content"
tools:context="com.testapp.myapplication.MainActivity">
<TextView
android:id="@+id/text_view_1"
android:layout_width="120dp"
android:layout_height="0dp"
android:background="@color/colorAccent"
android:text="Text View 1"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#22AA99"
android:text="Text View 2 Showing problem with overlap. Overlapping. Not O"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintLeft_toRightOf="@id/text_view_1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/text_view_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#FF00FF"
android:text="Text View 3"
android:textAppearance="@style/TextAppearance.AppCompat.Body2"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@id/text_view_1"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@id/text_view_2" />
</android.support.constraint.ConstraintLayout>
Thanks.
我从此发现
app:layout_constrainedHeight="true"
从约束布局1.1.0-beta2 https://androidstudio.googleblog.com/2017/10/constraintlayout-110-beta-2.html对wrap_content 施加约束。因此,我觉得这是正确的解决方案,因为这也允许我设置app:layout_constraintBottom_toBottomOf="parent"
这会在视图底部启用边距。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)