Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/34.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android:如何在TableLayout中截断TextView?_Android - Fatal编程技术网

Android:如何在TableLayout中截断TextView?

Android:如何在TableLayout中截断TextView?,android,Android,我在TableLayout的一列中有一个TextView。如果文本长度超过了列的容纳范围,我希望TextView截断并省略,但它只会拉伸列并破坏我的布局。我发现所有关于文本视图截断的建议都不起作用,我假设这是由于表的原因。有什么建议吗 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" androi

我在TableLayout的一列中有一个TextView。如果文本长度超过了列的容纳范围,我希望TextView截断并省略,但它只会拉伸列并破坏我的布局。我发现所有关于文本视图截断的建议都不起作用,我假设这是由于表的原因。有什么建议吗

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout  xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <TextView
        android:id="@+id/label"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </TextView>
    <RelativeLayout  
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        <ImageView 
            android:id="@+id/Icon"
            android:src="@drawable/icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </ImageView>
        <TextView 
            android:id="@+id/Value"
            android:layout_toRightOf="@id/Icon"
            android:text="very long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long stringvery long string"
            android:inputType="text"
            android:maxLines="1"
            android:ellipsize="end"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
        </TextView>
    </RelativeLayout>

您的xml和代码似乎与您所述的问题无关。不过,您是否尝试过为您的TextView使用android:singleLine=“true”。有关字幕,请参见


此外,您还可以使用
滚动视图
包装
表格布局
,以启用滚动。

您的xml和代码似乎与您所述的问题无关。不过,您是否尝试过为您的TextView使用android:singleLine=“true”。有关字幕,请参见

此外,您还可以使用
滚动视图
包装
表格布局
,以启用滚动。

您需要在包含文本视图的列上同时设置和:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:shrinkColumns="1"
    android:stretchColumns="1">     
        <TableRow>
            <View 
                android:background="#f00"
                android:layout_height="fill_parent"
                android:layout_width="40dp" />

            <TextView 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:textSize="18sp"
                android:textColor="#fff"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="Example text that is very loooooooooooooooooooooooooooooooooooooooooooooong" />

            <View 
                android:background="#00f"
                android:layout_height="fill_parent"
                android:layout_width="40dp" />
        </TableRow>

</TableLayout>

您需要在包含TextView的列上同时设置和:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="40dp"
    android:shrinkColumns="1"
    android:stretchColumns="1">     
        <TableRow>
            <View 
                android:background="#f00"
                android:layout_height="fill_parent"
                android:layout_width="40dp" />

            <TextView 
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:textSize="18sp"
                android:textColor="#fff"
                android:ellipsize="end"
                android:singleLine="true"
                android:text="Example text that is very loooooooooooooooooooooooooooooooooooooooooooooong" />

            <View 
                android:background="#00f"
                android:layout_height="fill_parent"
                android:layout_width="40dp" />
        </TableRow>

</TableLayout>


您能提供您的TableLayout xml吗?@Joe。我在代码中定义了它,我将代码添加到我的问题中作为编辑。你能提供你的TableLayout xml吗?@Joe。我在代码中定义了它,我将代码作为编辑添加到我的问题中。我尝试只添加singleLine=“true”,然后使用您的代码进行选框。两者都不起作用。A更喜欢截断,而不是使用scrollview进行包装。两者都不起作用。A更喜欢截断,而不是用scrollview包装。这也是我出错的地方,你必须告诉它哪些列索引应该收缩和增长。这也是我出错的地方,你必须告诉它哪些列索引应该收缩和增长。