Android启动画面:如何让它居中?

时间:2014-04-08 14:34:23

标签: android xml android-layout android-resources

我使用基于主题的解决方案,例如描述here, 在我的应用程序中显示启动画面 这是我的background_launch.xml:

<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:src="@drawable/launch_image"
android:tileMode="disabled" />

当我有launch_image作为png时,一切正常。但是,如果我使用@drawable/layerlist代替@drawable/launch_image,则应用会崩溃 layerlist.xml是:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item>
        <bitmap
            android:gravity="center"
            android:src="@drawable/launch_image"
            android:tileMode="disabled" >
        </bitmap>
    </item>
</layer-list>

应用程序崩溃时出现以下日志(跳过几行):

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.glu.pathlight/com.glu.pathlight.JSFinalNativeActivity}: android.content.res.Resources$NotFoundException: File res/drawable/background_launch.xml from drawable resource ID #0x7f020000
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2195)
        ...
Caused by: android.content.res.Resources$NotFoundException: File res/drawable/background_launch.xml from drawable resource ID #0x7f020000
    at android.content.res.Resources.loadDrawable(Resources.java:2096)
    at android.content.res.Resources.getDrawable(Resources.java:700)
    ... 11 more
Caused by: org.xmlpull.v1.XmlPullParserException: Binary XML file line #18: <bitmap> requires a valid src attribute
    at android.graphics.drawable.BitmapDrawable.inflate(BitmapDrawable.java:571)
    at android.graphics.drawable.Drawable.createFromXmlInner(Drawable.java:937)
    at android.graphics.drawable.Drawable.createFromXml(Drawable.java:877)
    at android.content.res.Resources.loadDrawable(Resources.java:2092)
    ... 22 more

我的资源出了什么问题?

2 个答案:

答案 0 :(得分:2)

把这个:

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item>
    <bitmap
        android:gravity="center"
        android:src="@drawable/launch_image"
        android:tileMode="disabled" >
    </bitmap>
</item>
</layer-list>

在您的background_launch.xml中,而非尝试在android:src <bitmap\>中引用状态列表

状态列表不是位图 - 这是错误告诉你的。

答案 1 :(得分:0)

检查你是否已将android:src =“@ drawable / launch_image”更改为android:src =“@ drawable / layerlist”。