在TableRow中创建多个TextView之一,不要包装文本

时间:2016-05-26 04:58:48

标签: android android-layout

鉴于下面的TableLayout,TableRow,我们如何使textView2中的文本不包装文本,同时使textView3中的文本包装文本?

<TableLayout
        style="@style/stdTableLayout" >

        <TableRow
            style="@style/standardTableRow" >
            <TextView
                style="@style/someActivityTableTextLeft"
                android:text="Some Title"
                android:id="@+id/textView2"/>

            <TextView
                style="@style/someActivityTableTextRight"
                android:text="A very very very long text to be displayed here"
                android:id="@+id/textView3"/>
        </TableRow>
</TableLayout>

standardTableRowsomeActivityTableTextLeftsomeActivityTableTextRight的样式定义如下。

<style name="stdTableLayout" parent="">
    <item name="android:layout_width" >match_parent</item>
    <item name="android:layout_height" >match_parent</item>
    <item name="android:layout_marginLeft" >10dp</item>
    <item name="android:layout_marginRight" >10dp</item>
</style>

<style name="standardTableRow" parent="">
        android:layout_width="match_parent"
        android:layout_height="match_parent"
</style>

<style name="someActivityTableTextLeft" parent="@android:style/TextAppearance">
        <item name="android:layout_width" >wrap_content</item>
        <item name="android:layout_height" >wrap_content</item>
        <item name="android:layout_weight" >1</item>
        <item name="android:textColor" >@android:color/black</item>
        <item name="android:paddingLeft" >0dp</item>
        <item name="android:textStyle" >bold</item>
        <item name="android:gravity" >left</item>
    </style>

    <style name="someActivityTableTextRight" parent="@android:style/TextAppearance">
        <item name="android:layout_width" >wrap_content</item>
        <item name="android:layout_height" >wrap_content</item>
        <item name="android:layout_weight" >1</item>
        <item name="android:textColor" >@android:color/black</item>
        <item name="android:paddingRight" >5dp</item>
        <item name="android:gravity" >right</item>
        <item name="android:textAppearance">?android:attr/textAppearanceSmall</item>
    </style>

1 个答案:

答案 0 :(得分:1)

textView2 singleline改为true

android:singleLine = "true"

Table Layout中,您还可以使用shrinkColumn属性缩小列。在你的情况下,它是第二个textview

<TableLayout style="@style/stdTableLayout"  shrinkColumn="1">

另见strechColumnscollapseColumns