Android开发记录二之线性、表格、相对布局

9 篇文章 0 订阅

1.LinerLayout 线性布局

android:gravity=""代表空间内文字基本位置,比如水平居中

android:weight=""代表权重,可以用数字表示,占总数的几分之几

android:singleLine=“”代表显示为1行,若字数很多,设置为true时,会用...表示剩余的字,设置为false时,会将所有的字显示出来

例如:

<?xml version="1.0" encoding ="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" > ->垂直布局
  <TextView 
      android:id="@+id/first"
      android:text="@string/ok"
      android:gravity="center_vertical"
      android:textSize="35pt"
      android:background="#aa0000"
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:paddingLeft="10dip"
      android:paddingTop="20dip"
      android:layout_weight="1"
      android:singleLine="true"
      />
</LinearLayout>

2.TableLayout 表格布局

    android:stretchColumns="2" 将某一列进行拉伸,从0开始计数

例子:

<?xml version ="1.0" encoding="utf-8"?>
<TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:stretchColumns="2" ->拉伸第三列
    >
    <TableRow>
        <TextView 
            android:id="@+id/a"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="3dip"
            />
          <TextView 
            android:id="@+id/b"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="3dip"
            />
          <TextView 
            android:id="@+id/c"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="3dip"
            />
        
    </TableRow>
     <TableRow>
        <TextView 
            android:id="@+id/d"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="3dip"
            />
          <TextView 
            android:id="@+id/e"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:padding="3dip"
            />
    </TableRow>
</TableLayout>

3.RelativeLayout 相对布局

padding 内边距

margin 外边距

比如marginleft=“10px” 左边外边距为10px,左边的空间要与它有10px的距离


        android:layout_above="" 将该控件置于指定id控件之上
        android:layout_below=""  将该控件置于指定id控件之下
        android:layout_toLeftOf="" 该控件右边与指定id控件左边对齐
        android:layout_toRightOf="" 该控件左边与指定id控件右边对齐
        
        android:layout_alignBaseline="" 该控件baseline和给定id控件baseline对齐
        android:layout_alignBottom="" 该控件底部和指定id控件底部对齐
        android:layout_alignLeft=""  该控件左边和指定id控件左边对齐
        android:layout_alignRight=""该控件右边和指定id控件右边对齐
        android:layout_alignTop="" 该控件顶部和指定id控件顶部对齐
        
        android:layout_alignParentLeft="" 如果为true,控件左边和父控件左边对齐
        android:layout_alignParentRight="" 如果为true,控件右边和父控件右边对齐
        android:layout_alignParentTop="" 如果为true,控件顶部和父控件顶部对齐
        android:layout_alignBottom="" 如果为true,控件底部和父控件底部对齐
         
        android:layout_centerHorizontal="" 如果为true,控件置于水平中央
        android:layout_centerVertical="" 如果为true,控件置于垂直中央
        android:layout_centerInParent="" 如果为true,置于父控件水平和垂直中央





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值