layout_span在TableLayout中的Andr​​oid [英] layout_span in TableLayout in Android

查看:166
本文介绍了layout_span在TableLayout中的Andr​​oid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想创建一个登录屏幕Android应用程序。我使用 TableLayout 来得到正确的定位。因此,两行组成的的TextView 的EditText ,我想补充一个按钮下面他们宽度被拉伸到屏幕上。所以,我把按钮在另一个的TableRow 和我添加 layout_span =2按钮,而按钮显示在第一列。

I would like to create a login screen for an android application. I'm using TableLayout to get the correct alignment. So two rows consist of a TextView and an EditText and I would like to add a Button below them that width is stretched to the screen. So I put the Button in another TableRow and I added layout_span="2" for the Button, but the Button is displayed in the first column.

我想这应该是正确的,但我必须做一些错误的XML文件。你有一个想法,什么是错的?

I think this should be correct, but I must do something wrong in the xml file. Do you have an idea what is wrong?

<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".LoginActivity"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" >
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="15dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/evUsername" />
        <EditText
            android:id="@+id/username"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="text" />
    </TableRow>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="15dp"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:text="@string/evPassword" />
        <EditText
            android:id="@+id/password"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:inputType="textPassword" />
    </TableRow>
    <TableRow
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <Button
            android:id="@+id/btnLogin"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_span="2"
            android:text="@string/btnLogin" />
    </TableRow>
</TableLayout>

在此先感谢!

推荐答案

目前我包我的 TableLayout 在结束的LinearLayout 和我添加了按钮 TableLayout

At the end I wrapped my TableLayout in a LinearLayout and I added the Button after the TableLayout.

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    tools:context=".LoginActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TableLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="15dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="@string/evUsername" />
            <EditText
                android:id="@+id/username"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:inputType="text" />
        </TableRow>
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="wrap_content" >
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingLeft="5dp"
                android:paddingRight="15dp"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:text="@string/evPassword" />
            <EditText
                android:id="@+id/password"
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:inputType="textPassword" />
        </TableRow>
    </TableLayout>
    <Button
        android:id="@+id/btnLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="@string/btnLogin" />
</LinearLayout>

这篇关于layout_span在TableLayout中的Andr​​oid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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