getWindow setBackgroundDrawable null 对UI优化的测试

               

今天工作不多,就测试了下 getWindow().setBackgroundDrawable(null);对UI优化的测试

OK首先我们用手机开发者模式自带的 OverDraw来判断布局的OverDraw状况,

随便写了一个默认布局

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#fff"    >    
<!--单纯就是个继承RelativeLayout的子类-->
    < com.xxx.widget.CustomRelativeLayout         android :layout_width= "300dp"         android :layout_height= "400dp"         android :background= "#fff">        < Button             android :layout_width= "wrap_content"             android :layout_height= "wrap_content"             android :layout_centerInParent= "true"             android :text= "按钮"/>    </ com.xxx.widget.CustomRelativeLayout></ RelativeLayout>

显示如上,我们可以看到 即使是根布局RelativeLayout也是有蓝色的,当然, 蓝色是可以接受的,但是button就彻底的飘红了,啥情况,有优化的余地么

当然有,

我们在onCreate的 setContentView 后加上这行代码

setContentView(R.layout.activity_test);getWindow().setBackgroundDrawable(null);
ps:window的默认毕竟色是白色,如果没了那就要在xml根布局自己把背景色白色加上,要不会有问题


我们可以看到, 这次根布局没有颜色了,蓝色移到了里面的RelativeLayout,,Button变成了绿色是我们想要的结果, 这样就避免了多一层overdraw了

           

再分享一下我老师大神的人工智能教程吧。零基础!通俗易懂!风趣幽默!还带黄段子!希望你也加入到我们人工智能的队伍中来!https://blog.csdn.net/jiangjunshow

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值