在Android 5.1.1中没有显示RelativeLayout中的drawable背景

时间:2015-08-07 06:35:15

标签: android android-layout android-drawable

我已经将一个drawable添加为RelativeLayout对象的背景(可以用位图绘制)。 这是我的代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                xmlns:tools="http://schemas.android.com/tools"
                xmlns:fbutton="http://schemas.android.com/apk/res-auto"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:paddingTop="@dimen/activity_vertical_margin"
                android:paddingBottom="@dimen/activity_vertical_margin"
                tools:context=".MainActivity"
                android:id="@+id/FirstSlideFrame"
                android:background="@drawable/background_darken">
</RelativeLayout>

和background_darken.xml(drawable):

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
        android:src="@drawable/new_bg"
        android:gravity="center_horizontal"/>

它在Android 2.2,2.3,4.2.2上运行良好,但在Android 5.1.1上没有显示图像。

任何想法如何解决它?

由于

Haim的。

编辑(模糊了某些部分......):

4.2.2 enter image description here 5.1.1 enter image description here

更新了activity_main.xml:

    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                    xmlns:tools="http://schemas.android.com/tools"
                    xmlns:fbutton="http://schemas.android.com/apk/res-auto"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:paddingLeft="@dimen/activity_horizontal_margin"
                    android:paddingRight="@dimen/activity_horizontal_margin"
                    android:paddingTop="@dimen/activity_vertical_margin"
                    android:paddingBottom="@dimen/activity_vertical_margin"
                    tools:context=".MainActivity"
                    android:id="@+id/FirstSlideFrame">
            <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:src="@drawable/new_bg"
                    android:scaleType="centerCrop"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="@style/TextAppearance.AppCompat.Large"
                    android:id="@+id/LogoText" android:layout_centerHorizontal="true" android:layout_marginTop="24dp"
                    android:textSize="72dp" android:textColor="#FFFFFF"/>
            <info.hoang8f.widget.FButton
                    android:layout_width="match_parent"
                    android:layout_height="72dp"
                    fbutton:buttonColor="#42A5F5"
                    fbutton:shadowColor="#1E88E5"
                    fbutton:shadowEnabled="true"
                    fbutton:shadowHeight="5dp"
                    fbutton:cornerRadius="5dp"
                    android:textSize="32dp"
                    android:textColor="#FFFFFF"
 android:layout_alignParentLeft="true"
                    android:layout_alignParentStart="true" android:layout_marginBottom="16dp"/>
            <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vestibulum scelerisque turpis vel aliquet mattis."
android:layout_centerHorizontal="true"
                    android:textColor="#FFFFFF"/>
            <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:textColor="#FFFFFF"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentRight="true" android:layout_alignParentEnd="true"/>
    </RelativeLayout>

1 个答案:

答案 0 :(得分:1)

基本上{API}从API级别18不推荐BitmapDrawable。如果您看到this.不建议使用它。因此它在最新的os版本中会有不同的行为。