如何获得TableLayout具有相等宽度的2列 [英] How to get a TableLayout with 2 columns of equal width

查看:173
本文介绍了如何获得TableLayout具有相等宽度的2列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的表有相等的列宽?下面是完整的布局:第一表,然后在的LinearLayout两个按钮表格之外,那些相等

Why doesn't my table have equal column widths? Here's the complete layout: first the table, then two buttons in a LinearLayout outside of table, those are divided equally.

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

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

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:padding="4dp" >

            <TableRow
                android:layout_marginTop="2dp"
                android:gravity="center_vertical" >

               <TextView
                    style="@style/Label.Plain"
                    android:layout_width="match_parent"
                    android:text="@string/Caption" />

                <EditText
                    android:background="#00ff00"
                    android:layout_width="match_parent"
                    android:layout_weight="1"
                    android:layout_height="@dimen/button_height"
                    android:inputType="numberDecimal"
                    android:selectAllOnFocus="true"
                    android:textSize="@dimen/spinner_text" />
            </TableRow>
        </TableLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginBottom="3dp"
            android:gravity="center_vertical"
            android:orientation="horizontal" >

            <Button
                android:id="@+id/btnOk"
                style="@style/Button.Plain.Fill"
                android:layout_weight="1"
                android:text="@string/ALS_OK" />

            <Button
                android:id="@+id/btnClose"
                style="@style/Button.Plain.Fill"
                android:layout_weight="1"
                android:text="@string/CANCEL" />
        </LinearLayout>
    </LinearLayout>

</ScrollView>

这是它的外观(一列绘能见度):

And here's how it looks (one column painted for visibility):

我可以在这里使用线性布局,只是想了解TableLayout使用的逻辑。

I could use linear layout here, just want to understand the logic TableLayout uses.

推荐答案

您可以用不同的方式获取此,

you can acquire this in different ways,

就像使用

android:stretchColumns="*" 

在TableLayout或

in TableLayout or

android:weightSum="1" 

在的TableRow以及

in TableRow and

 android:layout_width="0dp" 
 android:layout_height="wrap_content" 

在和的TableRow的任何意见。

in and any views in TableRow.

下面是一个例子

<?xml version="1.0" encoding="utf-8"?>       
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent">
        <TableLayout
            android:id="@+id/tblTop10List"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_centerInParent="true"
            android:layout_marginTop="23dp"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:weightSum="1" >

                <TextView
                    android:id="@+id/tvTopName"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:paddingLeft="8dp"
                    android:text="HELLO THERE"
                    android:textColor="#FFF000"
                    android:layout_column="0"
                    />

                <TextView
                    android:id="@+id/tvTopNumber"
                    android:paddingLeft="4dp"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:textColor="#FFF000"
                    android:text="HELLO THERE "
                    android:layout_column="1"
                    />
            </TableRow>
        </TableLayout>

    </LinearLayout>

**有关表格布局的详细信息和它的属性,请检查此好文章

** for more info about table layout and it's property please check this nice article

<一个href=\"http://www.informit.com/articles/article.aspx?p=2007353&seqNum=7\">http://www.informit.com/articles/article.aspx?p=2007353&seqNum=7

这篇关于如何获得TableLayout具有相等宽度的2列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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