gpt4 book ai didi

android - 约束布局指南

转载 作者:行者123 更新时间:2023-11-29 23:59:08 25 4
gpt4 key购买 nike

我正在尝试使用约束布局指南设置文本 block 的左右填充。我想要在两侧使用以下代码进行 11% 的填充。但是,当我尝试设置填充时,它没有反射(reflect)出来。当我只使用左侧或右侧时,它会显示,但在 TextView 上同时使用左侧和右侧准则时,填充不会反射(reflect)出来。

这是代码

            <android.support.constraint.ConstraintLayout
android:id="@+id/contentLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/centredIconLayout"
android:layout_centerHorizontal="true"
android:orientation="vertical">

<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:fontFamily="@font/gothamggm_bold"
android:layout_height="wrap_content"
android:layout_marginBottom="25dp"
android:text="@string/title_long"
android:textSize="17sp"
android:lineSpacingExtra="9sp"
android:textColor="@android:color/black"
app:layout_constraintLeft_toLeftOf="@+id/left_guideline"
app:layout_constraintRight_toLeftOf="@+id/right_guideline"
/>

<TextView
android:id="@+id/body"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginTop="13dp"
android:fontFamily="@font/gothamssm_book"
android:lineSpacingExtra="9sp"
android:text="@string/content_large"
android:textColor="@color/body_grey"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@+id/title"
app:layout_constraintLeft_toLeftOf="@+id/left_guideline"
app:layout_constraintRight_toLeftOf="@+id/right_guideline"
/>

<android.support.constraint.Guideline
android:id="@+id/left_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.11" />

<android.support.constraint.Guideline
android:id="@+id/right_guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintGuide_percent="0.89" />

</android.support.constraint.ConstraintLayout>

这是蓝图,其中两个 TextView (包含在@+id/contentLayout 中)都在 ImageView 下方 enter image description here

最佳答案

问题在于 TextView 的宽度。您已将其设置为 wrap_content。这就造成了问题。只需在布局编辑器中将其更改为 match_constraints 或在 xml 代码中手动将宽度设置为 0dp 即可正常工作。

关于android - 约束布局指南,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50119992/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com