简体   繁体   中英

Background drawable in RelativeLayout is not showed on Android 5.1.1

I have added a drawable as a background to a RelativeLayout object (drawable with bitmap). This is my code:

<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>

and background_darken.xml(the 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"/>

It works fine on Android 2.2, 2.3, 4.2.2 but on Android 5.1.1 the image is not showed.

Any Idea how to fix it?

Thanks

Haim.

EDIT (blurred some parts...):

4.2.2 在此处输入图片说明 5.1.1 在此处输入图片说明

Updated 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>

Basically BitmapDrawable is deprecated from API level 18. If you see this. Its not advisable to use it. So that it will have different behaviour in latest os versions.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM