Java Android设备未显示背景图像
我已经创建了一个项目,目标是eclipse建议的android 4.4-API级别19 无论如何,在模拟器上,一切看起来都很完美-下面是一个屏幕截图: 当我把它安装在我真正的设备上时,问题就来了——运行androidJava Android设备未显示背景图像,java,android,android-activity,Java,Android,Android Activity,我已经创建了一个项目,目标是eclipse建议的android 4.4-API级别19 无论如何,在模拟器上,一切看起来都很完美-下面是一个屏幕截图: 当我把它安装在我真正的设备上时,问题就来了——运行android4.1.2。除了背景图像外,一切都很完美,工作起来很有魅力。它显示的是白色背景,就像图片不存在一样 以下是我的xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" x
4.1.2
。除了背景图像外,一切都很完美,工作起来很有魅力。它显示的是白色背景,就像图片不存在一样
以下是我的xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity"
android:orientation="vertical"
android:gravity="center"
android:padding="30dp"
android:background="@drawable/wg_blurred_backgrounds_12"
>
<Button
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnTopJokes"
android:onClick="showTopJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnNewJokes"
android:onClick="showNewJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnAllJokes"
android:onClick="showAllJokes"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnMyFavorites"
android:onClick="showFavorites"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnCategories"
android:onClick="showCategories"
android:gravity="center"
/>
<Button
android:layout_marginTop="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/btnAddNewJoke"
android:gravity="center"
/>
</LinearLayout>
我知道我错过了一些非常小的东西,但作为初学者,我无法发现它。尝试删除用于绘图表名称的下划线。尝试使用较低分辨率的背景。你正在试的那个可能太大了。您可以在您的logcat中进行检查。在您的logcat中,您将看到如下消息:
位图太大,无法上载到纹理(2496x4437,max=4096x4096)
最大值为
4096x4096
,这是设备上运行的OpenGL版本的值GL\u max\u TEXTURE\u SIZE
。需要检查可绘制大小。添加四种分辨率的图像
将图像保存在每个可绘制文件夹中,如分辨率为xhdpi、xxhdpi、xxxhdpi的文件夹。减小图像的高度和宽度。这将解决问题。您还可以看到logcat生成的图像太大错误,您可能需要将其添加到清单文件中。 android:hardwareAccelerated=“false”,android:largeHeap=“true”
确保在可绘图文件中的图像文件旁边没有显示(24)
或(v 24)
,重新复制图像并将其保存为其中没有(24)
的类型,因为它将准备用于API 24
及以上版本,我的手机使用了这就是为什么我的API 23出现故障的原因API 23
您也可以尝试禁用硬件加速到您正在设置的背景视图
myView.setLayerType(View.LAYER\u TYPE\u软件,空)
然后设置背景是否在相应的可绘制文件夹中设置可绘制文件?检查这个@Raghunandan是的,一切都很好。我在模拟器上没有问题。我可以看到那里的背景。它没有显示在我的nexus s上,android
4.1.2
您是否尝试创建可绘制文件夹并将低分辨率背景放在其中?我遇到过这个问题,我不记得该怎么解决。但事实是这样的。一些lolipop设备不会显示更高分辨率的图像。这个修正有效。如果随机生成背景或使用一组图像将其加载到背景中,也可以通过编程手动调整位图的大小。
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/logo"
android:supportsRtl="true"
android:hardwareAccelerated="false"
android:largeHeap="true"
android:theme="@style/AppTheme">