多于两行时如何纠正ConstraintLayout TextView重叠

编程入门 行业动态 更新时间:2024-10-12 03:21:12
本文介绍了多于两行时如何纠正ConstraintLayout TextView重叠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在约束布局方面遇到问题,其中一个文本视图中的文本到达第二行将不会向下推另一个文本视图,该文本视图被限制在其下方,直到该行的中间为止.

I am having a problem with constraint layout where the text in one text view reaching the second line will not push down another text view that is constrained to be below it, until the middle of the line.

我用三个文本视图构建了一个简单的布局.第一个文本视图位于左侧并具有设置的宽度.第二个位于它与它的父对象之间的右边.第三个位于第二个下方,位于第一个的左侧.

I have built a simple layout with three text views. The first text view sits on the left and has a set width. The second one sits to the right of this, between it and its parent. The third sits below the second and to the left of the first.

我希望它看起来像:

I want it to look like:

但是,如果我删除文本"Not Overlapping".我得到:

However if I remove the text "Not Overlapping." I get:

它的改变点(不重叠"中的"O")似乎是当第一个文本视图"不存在时文本的长度填充两行时:

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:

那么,如何更改此布局,以便即使我在屏幕左侧有一个文本视图,也要在到达两行时立即将Text View 3向下推?而不是将其向下推到第二行的一半.

So how do I change this layout so that even when I have a text view on the left side of the screen it will push Text View 3 down as soon as it reaches two lines? As opposed to pushing it down half way through the second line.

我的XML:

<?xml version="1.0" encoding="utf-8"?> <android.support.constraint.ConstraintLayout xmlns:android="schemas.android/apk/res/android" xmlns:app="schemas.android/apk/res-auto" xmlns:tools="schemas.android/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>

谢谢.

推荐答案

从那时起我就找到了

app:layout_constrainedHeight="true"

来自约束布局 1.1.0-beta2 这会对wrap_content施加约束.因此,我认为这是正确的解决方案,因为这还允许我设置app:layout_constraintBottom_toBottomOf="parent",从而在视图底部启用边距.

from constraint layout 1.1.0-beta2 which enforce constraints on wrap_content. I therefore feel this is the correct solution as this also allows me to set the app:layout_constraintBottom_toBottomOf="parent" which enables a margin at the bottom of the view.

更多推荐

多于两行时如何纠正ConstraintLayout TextView重叠

本文发布于:2023-06-11 18:53:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/641405.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:ConstraintLayout   TextView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!