简体   繁体   English

android TextView没有换行

[英]android TextView no line break

I have a TableView with some table rows. 我有一些表行的TableView。 one of them is this (I have 2 of this structure in the table): 其中之一是这样的(我在表中有此结构的2个):

        <TableRow
            android:id="@+id/trTimeSettingEndTime"
            android:gravity="center_vertical"
            android:paddingTop="10dp"
            android:paddingBottom="3dp">

            <ImageView
                android:id="@+id/imageView2"
                android:layout_width="35dp"
                android:layout_height="35dp"
                android:paddingRight="10dp"
                android:src="@android:drawable/ic_menu_recent_history" />

            <TextView
                android:id="@+id/textView1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:textSize="16dp"
                android:text="Start Time" />

            <TextView
                android:id="@+id/tvTimeSettingEndTime"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:textSize="22dp"
                android:text="00:00"
                android:textColor="@color/dark_gray" />
        </TableRow>

the image is at the right size. 图像尺寸正确。 the middle textview takes out all the available space and the right textview width is it's content. 中间的textview会占用所有可用空间,而正确的textview宽度就是它的内容。

first thing I don't understand is why is the middle textview takes out all the space? 我不明白的第一件事是为什么中间的textview占用了所有空间?

second, when I change tvTimeSettingEndTime textview from code and it's a bit longer then the text break a line instead of adjusting it's width. 第二,当我从代码中更改tvTimeSettingEndTime textview时,它的时间更长了,然后文本中断了一行,而不是调整其宽度。

can someone explain why is the middle on taking most of the space? 有人可以解释为什么占据大部分空间吗?

how can I make it that the third line would adjust it's width according to the text I put into it from code? 如何使第三行根据我在代码中放入的文本来调整其宽度?

Thanks 谢谢

It sounds like you want the first column to be a static width (already working), the 3rd column to be the width of the contents (wrap_content), and the 2nd column to fill the available space. 听起来好像您希望第一列为静态宽度(已经工作),第三列为内容的宽度(wrap_content),第二列为可用空间。 If so, try using a weight + 0dp width for the 2nd column, and wrap_content for the 3rd column. 如果是这样,请尝试在第二列中使用权重+ 0dp宽度,在第三列中使用wrap_content。

    <TableRow
        android:id="@+id/trTimeSettingEndTime"
        android:gravity="center_vertical"
        android:paddingTop="10dp"
        android:paddingBottom="3dp">

        <ImageView
            android:id="@+id/imageView2"
            android:layout_width="35dp"
            android:layout_height="35dp"
            android:paddingRight="10dp"
            android:src="@android:drawable/ic_menu_recent_history" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="0dp"
            android:weight="1"
            android:layout_height="wrap_content"
            android:textSize="16dp"
            android:text="Start Time" />

        <TextView
            android:id="@+id/tvTimeSettingEndTime"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="22dp"
            android:text="00:00"
            android:textColor="@color/dark_gray" />
    </TableRow>

If you want the 2nd and 3rd to be equal widths, set them both to weight=1 and width=0dp. 如果希望第二和第三宽度相等,则将它们分别设置为weight = 1和width = 0dp。

Also keep in mind a TableLayout will force columns to be the same width for each row, if you are looking for each row's columns to size independently, try using two horizontal LinearLayouts instead. 还要记住,TableLayout将强制每一行的列宽度相同,如果您要查找每一行的列独立设置大小,请尝试使用两个水平LinearLayouts。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM