我已经看过很多这样的例子,与此有关的很多错误,由于某种原因,我的图像无法正常工作。
所有图像均小于.800x800像素,且小于200kb,并且均为.png格式。
我有几个片段,每个片段中都有几个图像。
我添加了带有背景图像的按钮,如下所示。
<LinearLayout 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"
android:orientation="vertical">
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please select" />
<Button
android:id="@+id/broad_btn"
android:layout_width="@android:dimen/notification_large_icon_width"
android:layout_height="@android:dimen/notification_large_icon_height"
android:background="@drawable/broad"
android:tag="broad"
android:text="Broad" />
</Linearlayout>
现在,我在第二个片段上的图像与上面的图像没有什么不同。
但是,当我尝试在后台使用它时,我的应用程序崩溃了。
但是,如果我在首页上使用“问题”图片-则效果很好。
只有当我将此图像移到第二个片段时,它才会失败。
第二个代码是
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView" />
<Button
android:id="@+id/late_btn"
android:layout_width="@android:dimen/notification_large_icon_height"
android:layout_height="@android:dimen/notification_large_icon_height"
android:background="@drawable/late"
android:text="Long" />
</LinearLayout>
最佳答案
对不起大家,
简直是一个RAM问题……没有对资源分配给予足够的重视。
谢谢,
。
关于android - 图像作为按钮背景-崩溃和工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44245106/