Android-约束布局不会遵守边距吗?

Android-约束布局不会遵守边距吗?,第1张

概述我是ConstraintLayout的新手,边距有麻烦.我有以下布局文件,但我试图使layoutNewsEventsItemImageContainer在左侧具有20dp的边距,同时将TextView保持在该边距的左侧.我究竟做错了什么???<?xmlversion="1.0"encoding="utf-8"?><android.support.constraint.ConstraintLayout

我是ConstraintLayout的新手,边距有麻烦.我有以下布局文件,但我试图使layoutNewsEventsItemImageContainer在左侧具有20dp的边距,同时将TextVIEw保持在该边距的左侧.

我究竟做错了什么???

<?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"        androID:ID="@+ID/layoutNewsEventsItemContainer"    androID:layout_wIDth="match_parent"    androID:layout_height="wrap_content"    androID:clickable="true"    androID:focusable="true"    androID:padding="20dp">    <TextVIEw        androID:ID="@+ID/lblNewsEventsItemheadline"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="TextVIEw"        app:layout_constraintRight_toleftOf="@+ID/layoutNewsEventsItemImageContainer"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_totopOf="parent"/>    <TextVIEw        androID:ID="@+ID/lblNewsEventsItemcopy"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:layout_margintop="10dp"        androID:text="TextVIEw"        app:layout_constraintRight_toleftOf="@+ID/layoutNewsEventsItemImageContainer"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_toBottomOf="@+ID/lblNewsEventsItemheadline"/>    <TextVIEw        androID:ID="@+ID/lblNewsEventsItemDateModifIEd"        androID:layout_wIDth="wrap_content"        androID:layout_height="wrap_content"        androID:text="TextVIEw"        app:layout_constraintRight_toleftOf="@+ID/layoutNewsEventsItemImageContainer"        app:layout_constraintStart_toStartOf="parent"        app:layout_constrainttop_toBottomOf="@+ID/lblNewsEventsItemcopy"/>    <androID.support.constraint.ConstraintLayout        androID:ID="@+ID/layoutNewsEventsItemImageContainer"        androID:layout_wIDth="75dp"        androID:layout_height="75dp"        androID:background="@color/Backgroundcolor2"        androID:layout_marginStart="20dp"        app:layout_constraintBottom_toBottomOf="parent"        app:layout_constraintEnd_toEndOf="parent"        app:layout_constrainttop_totopOf="parent">    </androID.support.constraint.ConstraintLayout></androID.support.constraint.ConstraintLayout>

正如您在下面的预览中所看到的,它切断了我的复制TextVIEw. TextVIEw应该保持在layoutNewsEventsItemImageContainer的左侧,并因此环绕到下一行.但是如您所见,没有应用任何边距.

@R_403_6120@:

按照建议,将文本视图放置在相对布局内.这将使您的约束布局可以在它知道的内容旁边对齐,而不是在可能会改变大小并因此导致重叠的textvIEw旁边对齐.您将获得可预期的行为.

<ConstraintLayout androID:ID="@+ID/layoutNewsEventsItemContainer"...<relativeLayoutandroID:ID="@+ID/container_for_textvIEw"androID:wIDth="wrap_content"androID:height="wrap_content"> <TextVIEw> ...first <TextVIEw> ...second <TextVIEw> ...third</relativeLayout><ConstraintLayout    androID:ID="@+ID/layoutNewsEventsItemImageContainer"    ....    app:layout_constraintEnd_toEndOf="@+ID/container_for_textvIEw"</ConstraintLayout></ConstraintLayout>//NewsEventsItemContainer
总结

以上是内存溢出为你收集整理的Android-约束布局不会遵守边距吗?全部内容,希望文章能够帮你解决Android-约束布局不会遵守边距吗?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://www.outofmemory.cn/web/1210091.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-04
下一篇 2022-06-04

发表评论

登录后才能评论

评论列表(0条)

保存