Android-看似无害的布局会导致应用程序在短时间使用后崩溃,不会出现任何错误
经过两天毫无结果的测试,我决定在这里发布我的问题,希望我错过了一些明显的东西 我将一个看似无害的xml布局简化为一个随机的图像、布局和滚动视图集合。这是:Android-看似无害的布局会导致应用程序在短时间使用后崩溃,不会出现任何错误,android,android-layout,android-xml,Android,Android Layout,Android Xml,经过两天毫无结果的测试,我决定在这里发布我的问题,希望我错过了一些明显的东西 我将一个看似无害的xml布局简化为一个随机的图像、布局和滚动视图集合。这是: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/wood_texture"
tools:context="com.testlayout.example.testlayout.MainActivity">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:src="@drawable/image_one"
android:id="@+id/imageOne"
android:adjustViewBounds="true"
android:layout_gravity="center_vertical"
android:visibility="visible"/>
<ImageView
android:layout_width="300dp"
android:layout_height="150dp"
android:background="@drawable/dark_wood_texture"
android:id="@+id/darkWood"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible"/>
<HorizontalScrollView
android:layout_width="300dp"
android:layout_height="150dp"
android:id="@+id/handScrollView"
android:scrollbars="none"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:paddingTop="10dp"
android:paddingBottom="10dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginBottom="20dp"
android:visibility="visible">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="@+id/handLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/image_three"
android:id="@+id/imageView"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/image_three"
android:id="@+id/imageView2"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/image_three"
android:id="@+id/imageView6"
android:adjustViewBounds="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"/>
</LinearLayout>
</HorizontalScrollView>
<ImageView
android:id="@+id/imageTwo"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/image_two_tiled"
android:scaleType="fitXY"/>
</RelativeLayout>
e2:我开始怀疑这是否是我手机的问题,而不是应用程序的问题,因为我可以在平板电脑上正常运行。我真的很想知道,如果其他人尝试在他们的Galaxy s6上运行此程序,是否会遇到此问题。特别是S6-这会告诉我这是我的手机还是所有S6的问题。
简而言之,是BitmapDrawable导致了整个问题。不幸的是,我无法解释为什么会解决此问题,但将使用位图的视图设置为layerType=“software”
将防止崩溃
- 在布局中:
android:layerType=“software”
- 在代码中:
view.setLayerType(view.LAYER\u TYPE\u软件,空)代码>
E/Resources: RunTimeException
android.content.res.Resources$NotFoundException: Resource ID #0x7f0202cf
at android.content.res.Resources.getValue(Resources.java:2558)
at android.content.res.Resources.startRC(Resources.java:1116)
at android.app.ActivityThread$mRunnable.run(ActivityThread.java:3056)
at java.lang.Thread.run(Thread.java:818)