本文介绍了Android Lollipop未显示android:背景图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了使用JPEG图像作为布局背景的屏幕.完整的UI屏幕在Android 8( GingerBread )到Android 19( Kitkat )中正确可见.布局背景在Android 20 +( Lollipop )

I have designed screen where I have used JPEG image as layout background. The complete UI screen is visible correctly in Android 8(GingerBread) to Android 19(Kitkat). The layout background is not visible in Android 20+(Lollipop)

我正在使用应用程序兼容性库.

请参见下面的屏幕截图

模拟器Android 8

设备奇巧

设备棒棒糖

解决方案已经尝试

  1. 创建另一个文件夹 mipmap ,然后在其中复制相同的图像,然后尝试使用@mipmap\image_background访问它. 什么都没有改变.
  1. Create another folder mipmap and copied the same image there and try to access it using @mipmap\image_background. Nothing changed.

布局XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    style="@style/mainBody"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
<!-- android:background="@drawable/login_bg"  -->
    <View
        android:id="@+id/vwStruts"
        android:layout_width="0dp"
        android:layout_height="0dp"
        android:layout_centerInParent="true" />


    <TableLayout
        android:id="@+id/tblLogin"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_margin="5dp"
        android:padding="5dp" >

        <TableRow
            android:id="@+id/tbrUserId"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            android:gravity="center" >

            <EditText
                android:id="@+id/edtUserId"
                style="@style/EditText"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:ems="10"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:hint="@string/hintEmpId" >
                <requestFocus />
            </EditText>
        </TableRow>

        <TableRow
            android:id="@+id/tbrPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="10dp"
            >

            <EditText
                android:id="@+id/edtPassword"
                style="@style/EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:ems="10"
                android:hint="@string/hintPassword"
                android:inputType="textPassword" />

        </TableRow>

        <TableRow
            android:id="@+id/tbrLoginAndClear"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:gravity="center" >

            <Button
                android:id="@+id/btnLogin"
                style="@style/LoginButton"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:minHeight="40dp"
                android:layout_weight="1"
                android:layout_marginLeft="5dp"
                android:layout_marginRight="5dp"
                android:text="@string/login" />
        </TableRow>
    </TableLayout>

    <ImageView
        android:id="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_above="@+id/tblLogin"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="@dimen/tblLoginMargin"
        android:src="@raw/footer_logo" />

</RelativeLayout>


styles.xml,没有用于值-v21的文件夹

 <resources xmlns:android="http://schemas.android.com/apk/res/android">

    <!--
        Base application theme, dependent on API level. This theme is replaced
        by AppBaseTheme from res/values-vXX/styles.xml on newer devices.

    -->
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
        <!--
            Theme customizations available in newer API levels can go in
            res/values-vXX/styles.xml, while customizations related to
            backward-compatibility can go here.

        -->
    </style>

    <!-- Application theme. -->
    <style name="AppTheme" parent="AppBaseTheme">
        <!-- All customizations that are NOT specific to a particular API-level can go here. -->
    </style>

</resources>

可绘制的登录按钮

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <!-- On Pressed state -->
    <item android:state_pressed="true" >
        <shape>
            <solid android:color="@color/btn_login_on_press" />
        </shape>

     </item>

    <!-- enabled true Not pressed, normal state -->
    <item android:state_pressed="false" android:state_enabled="true">
         <shape>
            <solid android:color="@color/btn_login_normal" />
        </shape>
    </item>

</selector>

添加了Styles.xml和按钮可绘制对象提及支持库的使用

推荐答案

经过长时间的测试和试验,我终于意识到..代码,xml或样式或主题设置没有问题.

After long time of test and trial, I finally realized..there is nothing wrong with the code or xml or styling or theme settings.

问题堆栈中的针尖是防止位图太大而无法上传到纹理android"

The little needle in the stack of issue was "Prevent bitmap too large to be uploaded into a texture android"

原因,当在屏幕OpenGLRenderer 上渲染图像时,没有为高分辨率设备加载位图 ,因此在连接设备上没有图像.

Reason, when rendering image on Screen OpenGLRenderer was not loading bitmap for high resolution devices and hence no image was coming on nexus devices.

我使用的解决方法是使用onCreate()方法以编程方式手动调整位图的大小,并将其设置为布局的背景.

The work around I used was to manually resize the bitmap progrmatically in onCreate() method and set as background for the layout.

希望它对无法加载背景的人有所帮助.

Hope it helps for anyone who is not able to load background.

随时查询更多!!

这篇关于Android Lollipop未显示android:背景图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-27 10:01