0

在我的应用程序中,我有 gridview。我希望它显示带有图像和一些文本视图的复杂项目。这是我的充气物品

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="250dp"
    android:layout_height="160dp" >

    <ImageView
        android:id="@+id/comics_cover"
        android:layout_width="120dp"
        android:layout_height="160dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/background_land"
        android:contentDescription="@string/contDescription_logo" />

    <ImageView
        android:id="@+id/cover_frame"
        android:layout_width="120dp"
        android:layout_height="160dp"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true"
        android:src="@drawable/frame"
        android:contentDescription="@string/contDescription_logo" />

...

在这里你可以看到一个 ID 为 Comics_cover 的 ImageView。它有一个来源,但这个来源将在我的自定义适配器的 getView 处被替换。

现在的问题是:我有 2 台设备来调试我的应用程序,TeXet TM7024,计算能力较弱,Nexus 7,计算能力强。TeXet 毫无问题地膨胀该 xml,但 Nexus 在我膨胀的那条线上崩溃。此外,Nexus 会根据屏幕方向给出不同的错误。此日志用于纵向

05-08 16:37:27.271: E/AndroidRuntime(15080): FATAL EXCEPTION: main
05-08 16:37:27.271: E/AndroidRuntime(15080): android.view.InflateException: Binary XML file line #8: Error inflating class <unknown>
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.createView(LayoutInflater.java:613)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at com.android.internal.policy.impl.PhoneLayoutInflater.onCreateView(PhoneLayoutInflater.java:56)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.onCreateView(LayoutInflater.java:660)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:685)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.rInflate(LayoutInflater.java:746)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.inflate(LayoutInflater.java:352)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at ru.tamzap.comics.ShopAdapter.getView(ShopAdapter.java:49)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.AbsListView.obtainView(AbsListView.java:2159)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.GridView.onMeasure(GridView.java:1040)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.View.measure(View.java:15518)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.View.measure(View.java:15518)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.View.measure(View.java:15518)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.measureChildBeforeLayout(LinearLayout.java:1404)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.measureVertical(LinearLayout.java:695)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.LinearLayout.onMeasure(LinearLayout.java:588)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.View.measure(View.java:15518)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewGroup.measureChildWithMargins(ViewGroup.java:4825)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.FrameLayout.onMeasure(FrameLayout.java:310)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at com.android.internal.policy.impl.PhoneWindow$DecorView.onMeasure(PhoneWindow.java:2176)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.View.measure(View.java:15518)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewRootImpl.performMeasure(ViewRootImpl.java:1874)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewRootImpl.measureHierarchy(ViewRootImpl.java:1089)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1265)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.Choreographer.doCallbacks(Choreographer.java:562)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.Choreographer.doFrame(Choreographer.java:532)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.os.Handler.handleCallback(Handler.java:725)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.os.Handler.dispatchMessage(Handler.java:92)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.os.Looper.loop(Looper.java:137)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at java.lang.reflect.Method.invoke(Method.java:511)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at dalvik.system.NativeStart.main(Native Method)
05-08 16:37:27.271: E/AndroidRuntime(15080): Caused by: java.lang.reflect.InvocationTargetException
05-08 16:37:27.271: E/AndroidRuntime(15080):    at java.lang.reflect.Constructor.constructNative(Native Method)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at java.lang.reflect.Constructor.newInstance(Constructor.java:417)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.view.LayoutInflater.createView(LayoutInflater.java:587)
05-08 16:37:27.271: E/AndroidRuntime(15080):    ... 46 more
05-08 16:37:27.271: E/AndroidRuntime(15080): Caused by: java.lang.OutOfMemoryError
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:785)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.content.res.Resources.loadDrawable(Resources.java:1965)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.content.res.TypedArray.getDrawable(TypedArray.java:601)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.ImageView.<init>(ImageView.java:120)
05-08 16:37:27.271: E/AndroidRuntime(15080):    at android.widget.ImageView.<init>(ImageView

这是用于景观的:

05-08 16:38:49.281: E/AndroidRuntime(15224): FATAL EXCEPTION: main
05-08 16:38:49.281: E/AndroidRuntime(15224): java.lang.OutOfMemoryError
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:502)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:355)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.graphics.BitmapFactory.decodeResource(BitmapFactory.java:378)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at ru.tamzap.comics.ImageHelper.decodeSampledBitmapFromResource(ImageHelper.java:49)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at ru.tamzap.comics.FormCovers$DownloadComics.prepareBackgrounds(FormCovers.java:166)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at ru.tamzap.comics.FormCovers$DownloadComics.onPostExecute(FormCovers.java:175)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at ru.tamzap.comics.FormCovers$DownloadComics.onPostExecute(FormCovers.java:1)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.os.AsyncTask.finish(AsyncTask.java:631)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.os.AsyncTask.access$600(AsyncTask.java:177)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:644)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.os.Handler.dispatchMessage(Handler.java:99)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.os.Looper.loop(Looper.java:137)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at android.app.ActivityThread.main(ActivityThread.java:5041)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at java.lang.reflect.Method.invokeNative(Native Method)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at java.lang.reflect.Method.invoke(Method.java:511)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
05-08 16:38:49.281: E/AndroidRuntime(15224):    at dalvik.system.NativeStart.main(Native Method)

有什么问题?有任何想法吗?

无论如何,我通过删除 ImageView 的源解决了这个问题。但我对这个错误的原因很感兴趣。

我想,这取决于源图像的大小,因为 ImageViw 几乎没有图像膨胀没有问题。但是,在那种情况下,为什么 TeXet “幸存”而 Nexus “倒下”?

4

0 回答 0