Android基础TOP3:Activity的线性,相对,帧和表格布局的概括

线性布局 LinearLayout:

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

 <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入注册用户名"/>
  <requestFocus />
  <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入密码"
        />

  <EditText
      android:layout_width="fill_parent"
      android:layout_height="wrap_content"
      android:ems="5"
      android:hint="请再次输入密码" >

  </EditText>

    <EditText
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:hint="请输入邮箱"/>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_margin="10dip"
        android:background="@drawable/btn_bg"
        android:gravity="center"
        android:hint="注册" />

</LinearLayout>

相对布局 RelativeLayout:

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <RelativeLayout
 3     xmlns:android="http://schemas.android.com/apk/res/android"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     >
 7
 8 <EditText
 9     android:id="@+id/e1"
10     android:layout_width="fill_parent"
11     android:layout_height="wrap_content"
12     android:hint="请输入用户名"
13     />
14 <EditText
15     android:id="@+id/e2"
16     android:layout_below="@id/e1"
17   android:layout_width="fill_parent"
18     android:layout_height="wrap_content"
19    android:hint="请输入用户名"    />
20
21 <Button
22     android:id="@+id/b2"
23       android:layout_below="@id/e2"
24       android:layout_alignRight="@id/e2"
25     android:layout_width="wrap_content"
26     android:layout_height="wrap_content"
27     android:text="注册"
28     />
29 <Button
30     android:id="@+id/b1"
31       android:layout_below="@id/e2"
32       android:layout_toLeftOf="@id/b2"
33     android:layout_width="wrap_content"
34     android:layout_height="wrap_content"
35     android:text="登录"
36     />
37
38 </RelativeLayout>

帧布局FrameLyaout:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView
        android:id="@+id/t1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:background="#f00"
        android:height="300dp"
        android:width="300dp" />

      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="#0f0"
          android:height="100dp"
          android:width="150dp" />
      <TextView
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:background="#00f"
          android:height="50dp"
          android:width="100dp" />

</FrameLayout>

表格布局TableLayout:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
    <TableRow >
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="name"
        android:paddingLeft="20dp"
        android:textSize="16dp"
        />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="20dp"
        android:textSize="16dp"
        />

       <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="20dp"
        android:textSize="16dp"
        />
</TableRow>
<TableRow>
   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="15dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
</TableRow>
<TableRow>
   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="15dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
</TableRow>
<TableRow>
   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="15dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
</TableRow>
<TableRow>
   <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="15dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
        <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="achievement"
        android:paddingLeft="40dp"
        android:textSize="8dp"
        />
</TableRow>
</TableLayout>

时间: 2024-08-09 22:31:25

Android基础TOP3:Activity的线性,相对,帧和表格布局的概括的相关文章

Android基础入门教程——2.4.8 ListView Item多布局的实现

Android基础入门教程--2.4.8 ListView Item多布局的实现 标签(空格分隔): Android基础入门教程 本节引言: 本节是ListView这个小节的最后一节,给大家带来的是ListView多布局Item的实现, 何为ListView Item多布局,打个比方,QQ这种聊天列表: 假如他是用一个ListView做的,那么一个ListView上不就有两种不同的Item咯! 一左一右,嘿嘿,本节就来教大家如何实现ListView的多布局! 1.要点讲解: 重写getItemV

Android基础_2 Activity线性布局和表格布局

在activity的布局中,线性布局和表格布局是最简单的,这次分别从线性布局,表格布局以及线性布局和表格混合布局做了实验,实验中只需要编写 相应的xml的代码,java代码不需要更改,因为我们这里只是练习android的界面设计.参考的资料为mars老师的教程. 线性布局: 线性布局就是将各种控件按照行或者列依次进行排列. 其中本实验用到的各控件的属性解释如下: android:layout_weight属性是指不同的控件在activity中占有体积大小的比例. android:paddingL

Android基础_3 Activity相对布局

相对布局要比前面讲的线性布局和表格布局要灵活一些,所以平常用得也是比较多的.相对布局控件的位置是与其周围控件的位置相关的,从名字可以看出来,这些位置都是相对的,确定出了其中一个控件的位置就可以确定另一个控件的位置了. 本次实验就是显示如下的activity: 其中只有2个button,1个textview,1个edittext. 在相对布局中,一般用到的控件属性解释如下: 在相对布局中有如下属性,解释如下: android:layout_above  为将该控件的底部放在指定id控件的上方 an

【Android】利用相对布局布置更新软件的style为主题对话框的Activity,利用layout_weight属性对表格布局的行划分

Android布局中,同样可以与网页的div布局,用百分比来指定宽度.同样也可以像vb,c#,或者网页中的absolute布局一样,利用style为主题对话框的Activity整出模态窗口.比如,如下图所示的布局,在现在各类的安卓应用中很常见的.同时,设定在这个安卓程序一开始就弹出一个更新软件的Activity.那该如何完成呢? 1.首先,先到res\values\string.xml中布置好各个组件的字体,当然你可以边做安卓工程边添加.命名的时候有一定的规则,指明这个字体,是在哪个Activi

Android零基础入门第29节:善用TableLayout表格布局,事半功倍

前面学习了线性布局和相对布局,线性布局虽然方便,但如果遇到控件需要排列整齐的情况就很难达到要求,用相对布局又比较麻烦,为此Android系统中提供了表格布局. 一.认识TableLayout 表格布局就是让控件以表格的形式来排列控件,只要将控件放在单元格中,控件就可以整齐地排列,使用TableLayout标签. TableLayout继承了 LinearLayout,因此它的本质依然是线性布局管理器.每次向TableLayout中添加一个TableRow,该TableRow就是一个表格行,Tab

Android基础TOP3:线性布局的特点,常用属性,及权重值

线性布局是一种让视图水平或者垂直布排列的布局: 常用属性: androuid:orientation :表示布局方向 取值vertical表示垂直布局 取值horizontal表示水平布局 android:gravity 表示视图对齐方式 内容包括 TOP,bottom,left,right,center_vertical,center_horizontal,center 可以使用"|"分割填写多个值 布局中的视图可以使用如下多个属性: android:layout_gravity 表

【Android基础】Activity启动模式以及Intent Flags 与 栈 的全面解析

Android开发的过程中,Intent是我们最常用Android用于进程内或进程间通信的机制. Intent主要用于2种情景下:发起意图 .广播 其底层实现原理不在此篇文章的讨论范围,以后会陆续更新上的. 下面我就根据近期学习,总结记录下Activity启动模式 及 Intent Flags 与 栈 的关联分析. 1.首先我们先搞清楚什么是栈: 栈是一种常用的数据结构,栈只允许访问栈顶的元素,栈就像一个杯子,每次都只能取杯子顶上的东西,而对于栈就只能每次访问它的栈顶元素,从而可以达到保护栈顶元

Android基础之Activity

一.什么是Activity Activity是Android四大组件之一,并且Activity是组件中的重中之重. Activity是为用户提供一个用于信息交互的窗口. 二.如何去创建Activity 1.新建一个继承Activity的子类 1 public class MainActivity extends Activity { 2 3 @Override 4 protected void onCreate(Bundle savedInstanceState) { 5 super.onCre

【Android基础】Activity的启动模式(android:launchMode)

在android里,有4种activity的启动模式,分别为: "standard" (默认) "singleTop" "singleTask" "singleInstance" 它们主要有如下不同: 1. 如何决定所属task "standard"和"singleTop"的activity的目标task,和收到的Intent的发送者在同一个task内,除非intent包括参数FLAG_