zoukankan      html  css  js  c++  java
  • 布局

    布局

    一、     线性布局:

    LinearLayout代表了线性布局,属性android:orientation指明了布局的方向,通常有horizontal(水平)或vertical(垂直)两种方向.

    对于每一个控件,都必须有android:layout_width和android:layout_height两个属性。他们的取值是fill_parent和wrap_content,前者是填满父控件,后者是仅包裹文字。

    二、     TableLayout布局,表格布局

    表格布局有TableRow构成。表示一行

    三、     相对定位布局:RelativeLayout

    android:layout_above=”@+id/idname” //将该控件的底部置于给定ID的控件之上。

    android:layout_below=”@+id/idname”//将该控件的顶部置于给定ID的控件之下

    android:layout_toLeftOf=”@+id/idname”//将该控件的右边缘和给定ID的控件的左边缘对齐

    android:layout_toRightOf=”@+id/idname”//将该控件的左边缘和给定ID的控件右边缘对齐

    android:layout_alignBaseline=”@+id/idname”//将该控件的Baseline和给定ID的控件的Baseline对齐

    android:layout_alignBottom=”@+id/idname”//将该控件的底部边缘和给定ID的控件的底部边缘对齐

    android:layout_alignLeft=”@+id/idname”//将该控件的左边缘和给定ID的控件的左边缘对齐

    android:layout_alignRight=”@+id/idname”//将该控件的右边缘和给定ID的控件的右边缘对齐

    android:layout_alignTop=”@+id/idname”//将该控件的顶部和给定ID的控件的顶部对齐

    android:alignParentBottom//如果该值为true,则将该控件的底部和父控件的底部对齐

    android:layout_alignParentLeft//如果该值为true,则将该控件的左边和父控件的左边对齐

    android:layout_alignParentRight//如果该值为true,则将该控件的右边和父控件的右边对齐

    android:layout_alignParentTop//如果该值为true,则将该控件的顶部和父控件的顶部对齐

    android:layout_centerHorizontal//如果该值为true,则控件被置于水平方向的中央

    android:layout_centerInParent//如果该值为true,则控件被置于父控件垂直和水平方向的中央

    android:layout_centerVertical//如果该值为true,则控件被置于垂直方向的中央

    示例代码:

    <?xmlversion="1.0"encoding="utf-8"?>

    <RelativeLayoutxmlns:android="http://schemas.android.com/apk/res/android"

    android:layout_width="fill_parent"

    android:layout_height="fill_parent"

    android:padding="10px"

    <TextViewandroid:id="@+id/label" 

    android:layout_width="fill_parent" 

    android:layout_height="wrap_content"android:text="请输入:"/>

    <EditTextandroid:id="@+id/txt"android:layout_width="fill_parent"android:layout_height="wrap_content"

    android:layout_below="@id/label"

     />

    <Buttonandroid:id="@+id/ok" 

    android:layout_width="wrap_content" 

    android:text="Ok" 

    android:layout_marginLeft="10px" 

    android:layout_height="wrap_content" 

    android:layout_below="@+id/txt" 

    android:layout_alignParentRight="true"/>

    <Buttonandroid:id="@+id/cancel" 

    android:layout_width="wrap_content" 

    android:text="Cancel" 

    android:layout_marginLeft="10px" 

    android:layout_height="wrap_content" 

    android:layout_toLeftOf="@id/ok"

    android:layout_alignTop="@id/ok"/>

    </RelativeLayout>

    效果图:


    四、     各种属性

    android:id-指定id

    android:text-指定文本

    android:grivity-指定控件的基本位置,如居中,居右

    android:textsize-指定文本字体大小

    android:background-指定背景

    android:width-指定控件文本宽度

    android:layout_width-指定控件宽度

    android:height-指定文本高度

    android:layout_height-指定控件高度

    android:padding*-指定控件内边距

    android:id-指定id

    android:sigleline-指定是否在一行显示

    android:stretchColumns-指定第几列为扩展列,也就是说如果指定该值为1,则剩余的空间由第二列补齐。多列可以由逗号分隔。用于均分各列。

  • 相关阅读:
    基于RMAN从活动数据库异机克隆(rman duplicate from active DB)
    包含min函数的栈
    栈的链表实现
    HDU 2196 树形DP Computer
    linux之access函数解析
    [置顶] sqlplus 使用笔记
    仿新浪微博登陆邮箱提示效果!
    找出数组中出现奇数次的元素<异或的应用>
    SOA体系结构基础培训教程-规范标准篇
    一个寻找.jar 和.zip文件中class文件的工具
  • 原文地址:https://www.cnblogs.com/itfenqing/p/4429533.html
Copyright © 2011-2022 走看看