android - 图像作为按钮背景-崩溃和工作

标签 android image button crash runtime

我已经看过很多这样的例子,与此有关的很多错误,由于某种原因,我的图像无法正常工作。

所有图像均小于.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/

相关文章:

android - 如何在android 4.2中显示选项菜单

android - 如何以编程方式删除 fab 的布局 anchor_property?

html - 带有 flexbox 的响应式 img

html - 关于如何使用 css 向图像添加透明渐变的任何想法?

python - 使用按钮更改变量的值 (Tkinter)

JavaScript 按钮停止页面上的所有音频

android - 删除数据库后 ContentProvider 未调用 onCreate

javascript - 获取图像实际大小 JS/Jquery

javascript - 测验应用程序 : Buttons in javascript are not functioning

android - 较新版本的 Android Studio 和只有两个可绘制目录 - drawable 和 drawable-v21