Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/390.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/228.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
Java Android Textview中的固定列_Java_Android_Listview_Textview_Android Linearlayout - Fatal编程技术网

Java Android Textview中的固定列

Java Android Textview中的固定列,java,android,listview,textview,android-linearlayout,Java,Android,Listview,Textview,Android Linearlayout,我试图在android中构建一个listview,但是有四列,它们都是相等的。我使用的是android:layout\u width=“0dp”和android:layout\u weight=“1”,这两个字段的列数相等,直到其中一个字段的文本大于其分配的列宽 我一直在试图找到一个解决方案来固定列的权重,这样额外的文本就可以理想地移动到下一行 这是我的listview布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayou

我试图在android中构建一个listview,但是有四列,它们都是相等的。我使用的是
android:layout\u width=“0dp”
android:layout\u weight=“1”
,这两个字段的列数相等,直到其中一个字段的文本大于其分配的列宽

我一直在试图找到一个解决方案来固定列的权重,这样额外的文本就可以理想地移动到下一行

这是我的listview布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="4">

    <TextView
    android:id="@+id/txvService"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:singleLine="false"/>

    <TextView
    android:id="@+id/txvScheduleDate"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:singleLine="false" />

    <TextView
    android:id="@+id/txvQty"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:singleLine="false" />

    <TextView
    android:id="@+id/txvBalance"
    android:layout_height="wrap_content"
    android:layout_width="0dp"
    android:layout_weight="1"
    android:singleLine="false" />

</LinearLayout>  


如果您有任何想法,我们将不胜感激。

使用
线性布局时
如果您有多个孩子,则需要添加
方向属性。使用
android:weightSum
按比例划分屏幕空间。在您的情况下,如果您添加

android:weightSum="4"
android:orientation="horizontal"

对于正好位于其“高度”属性下的LinearLayout洞口标记,它将导致线性布局在分配给它的空间上水平分配总重量为4的空间。从这里开始,每个元素的权重可以为1,这将使每个元素保留1/4的空间。还可以使用“权重/权重和”属性在线性布局中放置宽度不同的元素,即:两个权重为1和3的元素将第一个元素排列为水平空间的1/4,第二个元素排列为3/4

也许singleline=false有帮助?好主意,但我只是在所有文本视图中放置了android:singleline=“false”,但它没有帮助,它仍然在推送所有内容。你可能想检查一下:我正在尝试你的代码,多余的文本正在移到下一行。列的宽度相同,但高度不同。我刚刚意识到作为工作答案给出的建议,我只是在不同的布局中测试了我的代码。我的问题显然是在运行时它被放置在listview中。我确信这本身就是一个非常不同的问题。非常感谢你。