我编写了这段代码,但我不知道我遇到了什么问题以及如何解决它。 我想显示800个标题的列表,我想从要显示5秒钟的imageView开始,然后我要转到主页。当我尝试运行时,出现此错误:图像太大。我已经将图像转换为webp,现在的重量为1.9Mb。我不知道为什么图像太大?
public class activity_intro extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_intro);
ImageView img_intro = (ImageView) findViewById(R.id.img_intro); // Create an icon
Picasso.get().load(R.drawable.img_intro).into(img_intro);
new CountDownTimer(5000, 1000) {
public void onTick(long millisUntilFinished) {
}
public void onFinish() {
final Intent intro_toMain = new Intent(activity_intro.this, Activity_Main.class);
startActivity(intro_toMain);
}
}.start();
}
}
这是LogCat
06-29 14:00:17.710 28527-28527/com.huawei.b_happy.cantipopolari W/System.err: java.lang.RuntimeException: Canvas: trying to draw too large(113246208bytes) bitmap.
06-29 14:00:17.711 28527-28527/com.huawei.b_happy.cantipopolari W/System.err: at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:260)
at android.graphics.Canvas.drawBitmap(Canvas.java:1415)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:546)
at android.widget.ImageView.onDraw(ImageView.java:1301)
at android.view.View.draw(View.java:17256)
at android.view.View.updateDisplayListIfDirty(View.java:16221)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.support.constraint.ConstraintLayout.dispatchDraw(ConstraintLayout.java:1963)
at android.view.View.updateDisplayListIfDirty(View.java:16216)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.view.View.updateDisplayListIfDirty(View.java:16216)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.view.View.updateDisplayListIfDirty(View.java:16216)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.view.View.updateDisplayListIfDirty(View.java:16216)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.view.View.updateDisplayListIfDirty(View.java:16216)
at android.view.View.draw(View.java:17022)
at android.view.ViewGroup.drawChild(ViewGroup.java:3777)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:3560)
at android.view.View.draw(View.java:17259)
at com.android.internal.policy.DecorView.draw(DecorView.java:801)
at android.view.View.updateDisplayListIfDirty(View.java:16221)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:677)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:683)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:797)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2997)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2791)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2382)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1372)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6774)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:926)
at android.view.Choreographer.doCallbacks(Choreographer.java:735)
at android.view.Choreographer.doFrame(Choreographer.java:667)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:912)
at android.os.Handler.handleCallback(Handler.java:761)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:156)
06-29 14:00:17.712 28527-28527/com.huawei.b_happy.cantipopolari W/System.err: at android.app.ActivityThread.main(ActivityThread.java:6595)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:942)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:832)
答案 0 :(得分:1)
它表示图像尺寸太大。因此,使用-
Picasso.get().load(R.drawable.img_intro).resize(100, 200).centerCrop().into(img_intro);
其中100表示宽度,200表示高度。