android 03 TableLayout

本文介绍了一个简单的Android应用程序登录界面布局实现方法,使用TableLayout进行两行两列的用户名密码输入框布局,并设置了一行两个按钮(登录和退出)的布局。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

       

MainActivity.java(默认的,什么都没有)

package com.sxt.day02_02;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

}

 xml文件:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <TableLayout    2行2列,用户名密码
        android:layout_width="match_parent"    宽:占满一行
        android:layout_height="wrap_content"   高:
        android:stretchColumns="1" >        从0开始,1就是第二列,第一列内容有多宽就多宽,第二列把剩余全部占据

        <TableRow>            第一行

            <TextView android:text="用户名" />第一列。不设置宽和高,则根据文字大小来定。

            <EditText android:hint="2-10个字符" />第一列,
        </TableRow>

        <TableRow>

            <TextView android:text="密码" />

            <EditText
                android:hint="2-10个字符"
                android:password="true" />
        </TableRow>
    </TableLayout>

    <TableLayout                1行2列,登陆退出
        android:layout_marginTop="20dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="0,1" >        这2列都是自动扩展,平分当前行,

        <TableRow>

            <Button
                android:background="@drawable/btn_bg"
                android:drawableLeft="@drawable/login32x32"   左图右字
                android:padding="3dp"   内部间距
                android:text="登陆" 
                android:textColor="#fff"
                android:layout_gravity="center_horizontal"/>   水平居中

            <Button
                android:background="@drawable/btn_bg"
                android:drawableLeft="@drawable/exit32x32"
                android:padding="3dp"
                android:text="退出" 
                android:textColor="#fff"   文字颜色,白色
                android:layout_gravity="center_horizontal"/>  水平居中
        </TableRow>
    </TableLayout>

</LinearLayout>

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值