gpt4 book ai didi

Android:动态添加的 TextView 不换行文本

转载 作者:数据小太阳 更新时间:2023-10-29 02:45:24 24 4
gpt4 key购买 nike

将 TextView 动态添加到此布局会导致文本不换行。

<!-- R.layout.description_card -->
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/LinearLayout_InfoShow"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="@dimen/table_row_padding_bottom" >

<TableLayout
android:background="@drawable/card_bg"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TableRow
android:id="@+id/TableRow_DescriptionTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:id="@+id/DescriptionTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:textSize="@dimen/page_name_size"
android:text="Loading data..." />

</TableRow>
<TableRow
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/DescriptionTitle">

<LinearLayout android:id="@+id/LinearLayout_Description"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content">

<!-- Dynamically added TextView here -->

</LinearLayout>

</TableRow>
</TableLayout>

</LinearLayout>

我使用这些方法将 TextView 动态添加到此布局:

    View view = inflater.inflate(R.layout.description_card, null);
TextView title = (TextView) view.findViewById(R.id.DescriptionTitle);
LinearLayout description = (LinearLayout) view.findViewById(R.id.LinearLayout_Description);
ArrayList<TextView> textViews = des.getText();
Iterator<TextView> iter = textViews.iterator();
while(iter.hasNext()){
TextView textView = iter.next();
description.addView(textView);
}

这会导致我的 TextView 不会换行,即使我将 TextView 直接包含在 XML 文件中也能正常工作。

结果是这样的: screenshot

编辑: TextView 布局:

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TextViewDescription"
style="@style/AppTheme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:paddingRight="8dp"
android:text="Loading data..."
android:textSize="@dimen/description_size"
android:layout_weight="1"
android:ellipsize="none"
android:scrollHorizontally="false" />

最佳答案

您可能需要将其设置为多行。尝试

setInputType (InputType.TYPE_TEXT_FLAG_MULTI_LINE);

如果您有其他 InputType 属性,则需要将它们“或”在一起。

关于Android:动态添加的 TextView 不换行文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20012182/

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