我正在尝试使用滑动加载图像,它在Android 6.0中工作正常,但它的工作效果不如Android 6.0。我搜索过,但没有找到任何解决方案。我还增加了manifext.xml
中的堆大小。
我也尝试过Fresco和Picasso,但它始终是这个例外。我还尝试借助位图缩小图片的大小。
这是日志细节。
Increasing code cache capacity to 1024KB
05-28 23:24:46.255 9111-9111/com.romilandroid.shreekshatriya E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.romilandroid.shreekshatriya, PID: 9111
java.lang.RuntimeException: Canvas: trying to draw too large(144000000bytes) bitmap.
at android.view.DisplayListCanvas.throwIfCannotDraw(DisplayListCanvas.java:229)
at android.view.RecordingCanvas.drawBitmap(RecordingCanvas.java:97)
at android.graphics.drawable.BitmapDrawable.draw(BitmapDrawable.java:529)
at android.widget.ImageView.onDraw(ImageView.java:1367)
at android.view.View.draw(View.java:19123)
at android.view.View.updateDisplayListIfDirty(View.java:18073)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.draw(View.java:19126)
at android.view.View.updateDisplayListIfDirty(View.java:18073)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.draw(View.java:19126)
at android.support.v4.view.ViewPager.draw(ViewPager.java:2420)
at android.view.View.updateDisplayListIfDirty(View.java:18073)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.updateDisplayListIfDirty(View.java:18064)
at android.view.View.draw(View.java:18851)
at android.view.ViewGroup.drawChild(ViewGroup.java:4214)
at android.view.ViewGroup.dispatchDraw(ViewGroup.java:4000)
at android.view.View.draw(View.java:19126)
at com.android.internal.policy.DecorView.draw(DecorView.java:785)
at android.view.View.updateDisplayListIfDirty(View.java:18073)
at android.view.ThreadedRenderer.updateViewTreeDisplayList(ThreadedRenderer.java:643)
at android.view.ThreadedRenderer.updateRootDisplayList(ThreadedRenderer.java:649)
at android.view.ThreadedRenderer.draw(ThreadedRenderer.java:757)
at android.view.ViewRootImpl.draw(ViewRootImpl.java:2980)
at android.view.ViewRootImpl.performDraw(ViewRootImpl.java:2794)
at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:2347)
at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:1386)
at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:6733)
at android.view.Choreographer$CallbackRecord.run(Choreographer.java:911)
at android.view.Choreographer.doCallbacks(Choreographer.java:723)
at android.view.Choreographer.doFrame(Choreographer.java:658)
at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:897)
at android.os.Handler.handleCallback(Handler.java:789)
at android.os.Handler.dispatchMessage(Handler.java:98)
at android.os.Looper.loop(Looper.java:164)
at android.app.ActivityThread.main(ActivityThread.java:6541)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.Zygote$MethodAndArgsCaller.run(Zygote.java:240)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:767)
答案 0 :(得分:2)
Glide.with(mContext)
.load("your image drawable")
.error(android.R.drawable.ic_dialog_alert)
.override(320, 210)
.listener(new RequestListener<String, GlideDrawable>() {
@Override
public boolean onException(Exception e, String model, Target<GlideDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GlideDrawable resource, String model, Target<GlideDrawable> target, boolean isFromMemoryCache, boolean isFirstResource) {
return false;
}
})
.into(holder.ModelImage);
使用带滑动的.overrride加载较大的图像。因为你想要加载的图像有大尺寸。 而且你还可以做一件事:
<application
android:largeHeap="true">
</applicatino>
进入android应用程序清单,以便使用大堆大小的应用程序正常工作。 如果您发现任何错误,请回复。感谢
答案 1 :(得分:0)
在build.gradle中尝试这个
dependencies {
implementation ("com.github.bumptech.glide:glide:4.7.1") {
exclude group: "com.android.support"
}
implementation "com.android.support:support-fragment:26.1.0"
}
答案 2 :(得分:0)
试试这有助于您
在我的情况下 - 问题只发生在使用Android 7的Sumsung设备上,问题出在启动画面比例上。将高度改为1024 px后 - 一切都好了。
将您在drawable中的图像移动到mipmap-xxhdpi。您的图像是位图格式,因此您应该将图像放在mipmap文件夹中,然后它将起作用
打开您的drawable文件夹,检查所有图片的大小,并更改图片的大小。
答案 3 :(得分:0)
如果要从项目(而不是从Web)加载图像,则应将图像放置在“ mipmap文件夹”中而不是“可绘制文件夹”中,因为图像是位图格式。