Android的表布局对齐 [英] Android Table Layout Alignment

查看:179
本文介绍了Android的表布局对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的表布局如下图显示的数据。

I am using Table Layout to display data as shown below.

我想要做什么?

我想在第二列中的文本要左对齐和文字换行应在下一行,过流,你在图像中看到显示出来。

I want the Text in the second column to be aligned to the left and the text should wrap and be displayed in the next line and over flow as you see in the image.

code:

    <TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <ImageView
                android:id="@+id/place_category_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:contentDescription="ss"
                android:paddingRight="10dp"
                android:src="@drawable/icon_category"
                android:textAlignment="textStart" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:text="230 kms"
                android:textSize="16sp" >
            </TextView>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <ImageView
                android:id="@+id/place_category_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:contentDescription="ss"
                android:paddingRight="10dp"
                android:src="@drawable/icon_category"
                android:textAlignment="textStart" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:text="Hill Station, Wild Life"
                android:textSize="16sp" >
            </TextView>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <ImageView
                android:id="@+id/place_category_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:contentDescription="ss"
                android:paddingRight="10dp"
                android:src="@drawable/icon_category"
                android:textAlignment="textStart" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:text="Summer 23-40°C, Winter 10-32°C"
                android:textSize="16sp" >
            </TextView>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <ImageView
                android:id="@+id/place_category_icon"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:contentDescription="ss"
                android:paddingRight="10dp"
                android:src="@drawable/icon_category"
                android:textAlignment="textStart" />

            <TextView
                android:id="@+id/textView2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerVertical="true"
                android:layout_gravity="center"
                android:text="Tippus Drop, Tippus Summer Residence, Brahmashram, Cycling, Paragliding"
                android:textSize="16sp" >
            </TextView>
        </TableRow>
    </TableLayout>

它应该是什么样子

What it should look like

推荐答案

我能想到的最简单的方法是将包装每个的TableRow 的内容与的LinearLayout 是这样的:

The easiest way I can think of is to wrap each TableRow content with a LinearLayout like this:

<TableLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/tableLayout1"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >

                <ImageView
                    android:id="@+id/place_category_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:contentDescription="ss"
                    android:paddingRight="10dp"
                    android:src="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:text="230 kms"
                    android:textSize="16sp" >
                </TextView>
            </LinearLayout>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >

                <ImageView
                    android:id="@+id/place_category_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:contentDescription="ss"
                    android:paddingRight="10dp"
                    android:src="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:text="Hill Station, Wild Life"
                    android:textSize="16sp" >
                </TextView>
            </LinearLayout>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >

                <ImageView
                    android:id="@+id/place_category_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:contentDescription="ss"
                    android:paddingRight="10dp"
                    android:src="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:text="Summer 23-40°C, Winter 10-32°C"
                    android:textSize="16sp" >
                </TextView>
            </LinearLayout>
        </TableRow>

        <TableRow
            android:id="@+id/tableRow2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:paddingBottom="10dp" >

            <LinearLayout
                android:layout_width="wrap_content"
                android:layout_height="match_parent" >

                <ImageView
                    android:id="@+id/place_category_icon"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:contentDescription="ss"
                    android:paddingRight="10dp"
                    android:src="@drawable/ic_launcher" />

                <TextView
                    android:id="@+id/textView2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_centerVertical="true"
                    android:layout_gravity="center"
                    android:text="Tippus Drop, Tippus Summer Residence, Brahmashram, Cycling, Paragliding"
                    android:textSize="16sp" >
                </TextView>
            </LinearLayout>
        </TableRow>
    </TableLayout>

这是结果:

希望我正确地理解你的要求。

Hope I correctly understood your requirements.

这篇关于Android的表布局对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆