生命周期及布局

这里写图片描述

Android的框架图

>
这里写图片描述

活动周期流程图

这里写图片描述
注意:

onResume()方法在活动准备好和用户进行交互的时候调用
onPause()方法是不可操作但是可见
onStop()方法是不可见的

可以将活动分为三种生存期

1、完整生存周期

活动在onCreate()方法和onDestory()方法之间所经历的,就是完整周期。一般情况下,一个活动会在onCreate()方法中完成各种初始化操作,而在onDestory()方法中完成释放内存操作。

2、可见生存周期

活动在onStart()方法和onStop()方法之间经历的,就是可见生存期,在可见生存期内,活动对于用户总是可见的,即便有可能无法和用户进行交互。我们可以通过这两个方法,合理的管理那些对用户可见的资源。比如在onStart()方法中对资源进行加载,而在onStop()方法中对资源进行释放,从而保证处于停止状态的活动不会占用过多的内存。

3、前台生存周期

活动在onResume()方法和onPause()方法之间经历的,就是前台生存周期,在前台生存周期内,活动总是处于运行状态的,此时活动是可以和用户进行交互的,我们平时看到和接触到最多的也是这个状态下的活动。

LinearLayout布局

"********************在res\layout下的程序****************"
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:weightSum="3">

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="0dip"
       android:layout_weight="1">
       <Button
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:layout_weight="1"/>
       <LinearLayout
           android:orientation="vertical"
           android:layout_width="0dip"
           android:layout_height="match_parent"
           android:layout_weight="2">
           <Button
               android:layout_width="match_parent"
               android:layout_height="0dip"
               android:layout_weight="1" />
           <Button
               android:layout_width="match_parent"
               android:layout_height="0dip"
               android:layout_weight="1"/>
       </LinearLayout>



   </LinearLayout>
    <Button
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1"/>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dip"
        android:layout_weight="1">

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="3">
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1"/>
            <Button
                android:layout_width="match_parent"
                android:layout_height="0dip"
                android:layout_weight="1"/>
        </LinearLayout>
        <Button
            android:layout_width="0dip"
            android:layout_height="match_parent"
            android:layout_weight="1"
            />
    </LinearLayout>
</LinearLayout>

执行结果图:这里写图片描述

RelativeLayout的布局

RelativeLayout的属性

1、alignParentaLeft Right Bottom Top 是相对空间的上下左右
2、centerInParent centerVertical centerHorizontal
是相对于父空间的中心、水平中心和垂直中心
3、toLeftOf toRightOf above below 相对后边跟id的那个控件上下左右
4、alignLeft alignRight alignBottom alignTop 是相对后边跟的id那个控件上下左右边对齐
5、layout_alignBaseline是基准线对齐

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值