Android应用复习一_布局

          选择从布局开始复习,是因为布局可以理解为容器,没有容器,用什么来装组件?

          在MainActivity中代码如下:

public class Android_LinearLayoutActivity extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.linearlayout);
    }
}

           在安卓中,目前流行的有四大布局:线性布局、相对布局、帧布局、表格布局。下面一一复习:

          线性布局:

        

<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" > 
</LinearLayout>

            orientation ——布局方向

layout_gravity——相对父控件的重心

gravity——自身内部的重心

 layout_margin——相对于父控件的外边距

padding——自身内部的内边距

layout_weight——权重,将布局内除去组件的剩余空间进行分配。

权重常用的方式为将组件设置为0,进行均衡分配空间。

 线性布局,无论横向还是纵向,每列(行)只能放入一个组件,所有组件呈线性排列。它是目前最常用的布局之一。

 

相对布局:

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

 


1.相对布局的控件按先后顺序层叠,后写入的组件覆盖先写入的。

2.看图

 

3.控件的可见:visibility:gone(消失且不占位置)invisible(消失但占据位置)visible(可见)。

 

帧布局:

帧布局容器为每个加入其中的组件创建一个空白的区域(称为一帧),所有每个子组件占据一帧,这些帧都会根据Gravity属性执行自动对其,也就是说帧布局的效果有点类似于awt编程中的CardLayout,都是把组件一个个的叠加在一起。

<?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"
    android:orientation="vertical" 
    android:layout_gravity="center">

</FrameLayout>

 

 

 

 

表格布局:

 

1.表格布局支持gravity,但是不支持layout_gravity。

2.一行的表示

<TableRow 
        android:layout_gravity="top">
       </TableRow> 

不写时,默认一个组件一行

3.行内组件使用layout_margin,会直接撑开row。

4.layout_column指定当前控件所在单元格。

5.layout_span合并单元格 =3 即合并三个

6.支持使用layout_weight权重。

7.ImageView画线法

<ImageView android:layout_width="fill_parent"
             android:layout_height="3dip"
             android:src="#F00"/>

                
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值