006表格布局管理器

1.      用TableRow标记来添加表格行

2.      如果不用tablerow的话,一个元素就占一行

3.      可以设置那些列被隐藏,可拉伸,可收缩

4.      主要3个属性collapseColumns,stretchColumns,shrinkColumns

1.  android:collapseColumns=""设置那些列可以被隐藏,其值为列的序号,列序号从0开始
等于1是就是隐藏第二列,要隐藏多列的时候用,分隔
2.  android:stretchColumns="1" 被拉伸,如果设置那个属性被拉伸,则会自动拉伸,
使用布局管理器多余的部分,要设置多个,也用,隔开,也是从0开始,其值也是列号
3.  android:shrinkColumns="1" 被收缩,如果设置那个属性可以别收缩,则当有些组件超出界面显示范围的时候,会收缩这个组件,
让其他组件可以显示
实例,实现喜马拉雅的登录界面
 
<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Main2Activity"
    android:stretchColumns="0,3">

    <TableRow
        android:paddingTop="200dp">
        <TextView />
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="账  号:"
            android:textSize="18sp"
            android:gravity="center_horizontal"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="邮箱或手机号"/>
        <TextView />
    </TableRow>
    <!--tablerow设置表格行

    第一个textview不设置任何属性,用于拉伸,使得不管屏幕宽不宽,都可以让中间的显示在中间(虽然是
    讲课时这么讲的,但还是不怎么理解)

    android:gravity="center_horizontal"(居中显示。这个我也不怎么理解)(理解一点了,在这个表格格子中居中)
    -->



    <TableRow>
        <TextView />
        <TextView
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:text="密  码::"
            android:textSize="18sp"
            android:gravity="center_horizontal"/>

        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="输入6-16位数字或字母"/>
        <TextView />
    </TableRow>

    <TableRow>
        <TextView/>
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="注  册"
            android:textSize="18sp"
            />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="登  录"
            android:background="#ff8247"
            />
    </TableRow>
    <TableRow
        android:paddingTop="20dp">
        <TextView />
        <TextView />
        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="忘记密码?"
            android:textColor="#ff4500"
            android:gravity="right"/>
        <TextView />
        <!--android:gravity="right"(在表格格子中)右对齐-->
    </TableRow>

</TableLayout>
 
 
 
 
 

猜你喜欢

转载自blog.csdn.net/qq_38309980/article/details/80887074
今日推荐