gpt4 book ai didi

android - 宽度为 "wrap_content"的多行 TextView

转载 作者:可可西里 更新时间:2023-11-01 19:03:28 26 4
gpt4 key购买 nike

我想知道如何让 TextView 在多行中显示其内容 without hardcoding the width in the XML .

    <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>

<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>

</LinearLayout>

欢迎任何想法。

编辑:我的问题是,当文本超过设置的宽度时(因为它到达了屏幕的末尾),一部分文本就不会显示。我希望文本分成两行

最佳答案

虽然我无法重现不环绕的问题,但您可以通过在第一个 TextView 上使用 weight 来解决定位问题。使用以下 XML 在 Eclipse 的图形布局 View 中提供预期的输出:

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="right"
android:orientation="horizontal">

<TextView
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:singleLine="false"
android:text="Long multiline text"/>

<TextView
android:textColor="@color/text_color"
android:layout_width="130dp"
android:layout_height="wrap_content"
/>

</LinearLayout>

关于android - 宽度为 "wrap_content"的多行 TextView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15258522/

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