Android开发必会App启动优化,腾讯T3大牛亲自教你

2、闪屏Activity优化:
Activity的UI层级优化:

优化前UI布局:

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@mipmap/icon_splash_bg”>

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:src=“@mipmap/icon_splash_word”

android:layout_centerVertical=“true”

android:layout_centerHorizontal=“true”

android:paddingBottom=“160dp”

/>

<ImageView

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_centerHorizontal=“true”

android:src=“@mipmap/icon_splash”

android:layout_alignParentBottom=“true”

android:layout_marginBottom=“@dimen/dp_41”

/>

<com.pxwx.student.modulecore.widget.TouchRelativeLayout

android:id=“@+id/rl_adsRl”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:gravity=“center_horizontal|top”

android:orientation=“vertical” >

<ImageView

android:id=“@+id/iv_SplashAd”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@null”

android:contentDescription=“@null”

android:scaleType=“fitXY”

android:visibility=“gone” />

</com.pxwx.student.modulecore.widget.TouchRelativeLayout>

<TextView

android:id=“@+id/tv_adjump”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:background=“@drawable/ad_jump_selector”

android:gravity=“center_vertical|center_horizontal”

android:layout_alignParentRight=“true”

android:layout_marginRight=“@dimen/dp_18”

android:layout_marginTop=“@dimen/dp_30”

android:paddingBottom=“@dimen/dp_5”

android:paddingLeft=“@dimen/dp_11”

android:paddingRight=“@dimen/dp_11”

android:paddingTop=“@dimen/dp_5”

android:text=“跳过 3”

android:textColor=“@color/white”

android:textSize=“@dimen/font_15”

android:visibility=“gone”

/>

简化后:

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@drawable/welcome_layler_drawable”>

<ViewStub

android:id=“@+id/vs”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout=“@layout/layout_stub_avd” />

ViewStub 初始化延迟

针对项目中的启屏广告业务,通过ViewStub延后他们的初始化,在需要显示的时候通过ViewStub的inflate显示真正的view,优化如下

<ViewStub

android:id=“@+id/vs”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:layout=“@layout/layout_stub_avd” />

开屏广告业务布局抽取

layout_stub_avd.xml

<?xml version="1.0" encoding="utf-8"?>

<com.pxwx.student.modulecore.widget.TouchRelativeLayout xmlns:android=“http://schemas.android.com/apk/res/android”

android:id=“@+id/rl_adsRl”

android:layout_width=“match_parent”

android:layout_height=“match_parent”>

<ImageView

android:id=“@+id/iv_SplashAd”

android:layout_width=“match_parent”

android:layout_height=“match_parent”

android:background=“@null”

android:contentDescription=“@null”

android:scaleType=“fitXY” />

<TextView

android:id=“@+id/tv_adjump”

android:layout_width=“wrap_content”

android:layout_height=“wrap_content”

android:layout_alignParentRight=“true”

android:layout_marginTop=“@dimen/dp_30”

android:layout_marginRight=“@dimen/dp_18”

android:background=“@drawable/ad_jump_selector”

android:gravity=“center”

android:paddingLeft=“@dimen/dp_11”

android:paddingTop=“@dimen/dp_5”

android:paddingRight=“@dimen/dp_11”

android:paddingBottom=“@dimen/dp_5”

android:text=“跳过 3”

android:textColor=“@color/white”

android:textSize=“@dimen/font_15” />

</com.pxwx.student.modulecore.widget.TouchRelativeLayout>

然后在代码中需要显示webview时进行inflate:

/**

  • 懒加载广告视图

*/

private void showAvd() {

viewStub = findViewById(R.id.vs);

if (viewStub != null) {

viewStub.inflate();

mAdRl = findViewById(R.id.rl_adsRl);

mAdImage = findViewById(R.id.iv_SplashAd);

mAdJump = findViewById(R.id.tv_adjump);

}

}

优化点:

  1. 废弃之前的启屏页UI布局,直接使用先前自定义好的welcome_layler_drawable作为启屏页背景

  2. 将开屏广告Ui抽取分离

  3. 懒加载广告视图

自我介绍一下,小编13年上海交大毕业,曾经在小公司待过,也去过华为、OPPO等大厂,18年进入阿里一直到现在。

深知大多数初中级安卓工程师,想要提升技能,往往是自己摸索成长,但自己不成体系的自学效果低效又漫长,而且极易碰到天花板技术停滞不前!

因此收集整理了一份《2024年最新Android移动开发全套学习资料》送给大家,初衷也很简单,就是希望能够帮助到想自学提升又不知道该从何学起的朋友,同时减轻大家的负担。
img
img
img
img

由于文件比较大,这里只是将部分目录截图出来,每个节点里面都包含大厂面经、学习笔记、源码讲义、实战项目、讲解视频
如果你觉得这些内容对你有帮助,可以添加下面V无偿领取!(备注Android)
img

由于篇幅原因,这份面试宝典已经被整理成了PDF文档,有需要Android面试宝典全套完整文档的麻烦点赞+点击GitHub即可获取资料免费领取方式!

本文在开源项目:GitHub中已收录,里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

V无偿领取!(备注Android)**
[外链图片转存中…(img-PedY07EU-1711354138632)]

由于篇幅原因,这份面试宝典已经被整理成了PDF文档,有需要Android面试宝典全套完整文档的麻烦点赞+点击GitHub即可获取资料免费领取方式!

[外链图片转存中…(img-qQcP78UC-1711354138632)]

本文在开源项目:GitHub中已收录,里面包含不同方向的自学编程路线、面试题集合/面经、及系列技术文章等,资源持续更新中…

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值