-1

当我想把我的img从drawable放到我的活动中时

<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"
    android:gravity="center_horizontal"
    android:background="@drawable/bg"> <-------------------(here)
....
..
</LinearLayout>

android studio中没有问题,但是当我用模拟器运行它时,我的应用程序无法打开,它自动关闭,那么如何将我的img放到我的布局中?

这是日志错误

E/AndroidRuntime: FATAL EXCEPTION: main
    Process: com.example.soalmasuk, PID: 3716
    java.lang.RuntimeException: Canvas: trying to draw too large(149107744bytes) bitmap.
        at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
        at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
        at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:545)
        at android.view.View.getDrawableRenderNode(View.java:17314)
4

1 回答 1

0

看起来您的图像太大并且您的模拟器没有足够的内存,请尝试减小图像大小并增加模拟器的内存。

在任何情况下,将大图像放在背景中都不是一个好习惯。

于 2020-02-07T02:17:21.197 回答