我是 Android 编程新手,在 ADT 中的一个非常简单的示例中遇到问题。我在 FrameLayout 中只有两个 ImageView,但是当我用手机测试它时,应用程序变得非常慢,因为它没有任何逻辑,因为我没有接触 java 文件夹。
这是我遇到的错误
12-16 16:17:43.261 18238-18238/com.example.brank.acocinapp I/Choreographer: Skipped 64 frames! The application may be doing too much work on its main thread.
12-16 16:17:44.781 18238-18248/com.example.brank.acocinapp W/art: Suspending all threads took: 26.044ms
12-16 16:17:44.831 18238-18238/com.example.brank.acocinapp W/PathParser: Points are too far apart 4.000000596046461
这是我的 content_main.xml 的 xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="com.example.brank.acocinapp.MainActivity">
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/frameLayout2"
android:layout_alignParentBottom="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView3"
android:adjustViewBounds="true"
android:src="@drawable/home2" />
</FrameLayout>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/frameLayout"
android:layout_alignParentTop="true">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView2"
android:src="@drawable/home1"
android:adjustViewBounds="true"/>
</FrameLayout>
</RelativeLayout>
我必须提到,如果我评论两个 FrameLayout 之一,问题就不存在。
编辑
我还将这两个图像放入了Drawable文件夹中(我不知道这是否会影响),但我在教程中看到我必须将图像放入Drawable中的子文件夹中(mdpi,hdpi,xhdpi,xxhdpi)问题是这个子文件夹不存在,所以我将图像粘贴到 Drawable 中。
最佳答案
好吧,可能发生的情况是操作系统正在尝试对您的图像进行大量处理,您可能选择了高分辨率。您可以做的是尝试创建图像的多种分辨率(mdpi、hdpi、xhdpi、xxhdpi)。您可以将图像的标准尺寸作为mdpi,并分别按1.5、2、3的比例增加hdpi、xhdpi、xxhdpi的尺寸。当你有这些图像时,将它们放入可绘制文件夹中,如果没有,请自行创建它们。有时这甚至可能导致 android 中的 OOM。一篇文章explaining它。
关于java - 安卓错误 "The application may be doing too much work on its main thread",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34315804/