Android透支背景。怎么设置正确?

时间:2013-11-04 12:39:39

标签: android performance background

我知道有很多主题有相同的请求,但我无法解决我的应用程序的后台问题。 如果我写这样的代码:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top|center"
android:orientation="vertical"
android:background:"@drawable/wallpaper>

我收到错误Lint:“可能透支:根元素描绘背景......

所以我改变了这个:

style.xml

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:windowBackground">@null</item>
</style>

<style name="WallpaperTheme" parent="@style/AppTheme">
    <item name="android:background">@drawable/wallpaper</item>
</style>

的manifest.xml

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:hardwareAccelerated="true"
    android:allowBackup="true"
    android:theme="@style/AppTheme">
    <activity
        android:name=".Main"
        android:label="@string/title_activity_main"
        android:theme="@style/WallpaperTheme">
        ...
        ...
    </activity>

这样不再接收错误Lint但应用程序的布局错误,例如: image 按钮也没有遵循正确的布局...... 那我该怎么办?

2 个答案:

答案 0 :(得分:2)

我很蠢! 我以这种方式更改了代码,Lint的错误不再出现:

<强> style.xml:

<style name="AppTheme" parent="@android:style/Theme.Holo">
    <item name="android:windowBackground">@null</item>
</style>

<强>的manifest.xml

<application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:hardwareAccelerated="true"
        android:allowBackup="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".Main"
            android:label="@string/title_activity_main">
            ...
            ...
        </activity>

<强> layout.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:layout_gravity="top"
   android:orientation="vertical"
   android:background="@drawable/wallpaper">

答案 1 :(得分:0)

您真的需要更改应用主题吗?在我看来,你只是想改变活动的背景,并将布局背景作为活动背景...为什么你

  1. 更改应用主题?
  2. 更改windowBackground而不仅仅是背景?
  3. 在这里,您基本上通过将布局设置为null decorview来更改布局本身的容器/父级。您不需要这个,这就是影响线性布局放置的原因。