透支和罗曼盖伊的博客文章Android的性能案例研究 [英] Overdraw and Romain Guy's blog post Android Performance Case Study

查看:223
本文介绍了透支和罗曼盖伊的博客文章Android的性能案例研究的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基于罗曼盖伊的博客文章 Android的性能案例研究在谈到透支,他这样说:

Based upon Romain Guy's blog post Android Performance Case Study when talking about Overdraw he says this:

删除窗口背景:在你的主题定义的背景所使用的系统中启动应用程序时创建preVIEW窗口。千万不要将它设置为null,除非你的应用程序是透明的。相反,将其设置为你想要得到或致电getWindow()。setBackgroundDrawable(空)的的onCreate()去掉的颜色/图像。 *

Removing the window background: the background defined in your theme is used by the system to create preview windows when launching your application. Never set it to null unless your application is transparent. Instead, set it to the color/image you want or get rid of from onCreate() by calling getWindow().setBackgroundDrawable(null).*

不过getWindow()。setBackgroundDrawable(空)似乎没有任何效果。下面是与code的例子:

However getWindow().setBackgroundDrawable(null) seems to have no effect. Here's a sample with the code:

//MainActivity
@Override
protected void onCreate(Bundle savedInstanceState) {
    getWindow().setBackgroundDrawable(null);
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
}

// main.xml
<RelativeLayout 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:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:background="#FFE0FFE0"
tools:context=".MainActivity" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginLeft="40dp"
    android:layout_marginRight="40dp"
    android:background="#FFFFFFE0" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="40dp"
        android:text="@string/hello_world" />
</LinearLayout>

// styles.xml
<style name="AppTheme" parent="AppBaseTheme">
   <item name="android:windowBackground">@color/yellow</item>
</style>

此示例产生的结果的图像中。你可以看到外层具有透支和窗口背景色是仍然可见。我希望窗口的背景消失,只有lineralayout有透支。

This sample produces the results in the image. You can see the outerlayer has an overdraw and the window background color is still visible. I expected the window's background to be gone and only the lineralayout to have overdraw.

推荐答案

刚刚移动 getWindow()。setBackgroundDrawable(空)下来,直到在任何地方后的setContentView(R.layout.main);例如:

Just move getWindow().setBackgroundDrawable(null) down, until anywhere after setContentView(R.layout.main); e.g.:

@Override public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    getWindow().setBackgroundDrawable(null);
}

的setContentView(...)通话设置传播活动连接到也可能是窗口中的内容将覆盖你的意思是用<$ C $所做的更改C> setBackgroundDrawable(空)。

The setContentView(...) call propagates setting the content on the window the activity is attached to and probably overrides the change you meant to made with setBackgroundDrawable(null).

结果:

这篇关于透支和罗曼盖伊的博客文章Android的性能案例研究的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆