在我的应用程序中,我有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“垮掉”了?