gpt4 book ai didi

java - 水平 ScrollView 崩溃

转载 作者:行者123 更新时间:2023-12-02 11:45:39 26 4
gpt4 key购买 nike

我需要在屏幕上显示多个图像,允许用户以水平方式滑动。当他们单击图像时,他们应该从应用程序本身的站点打开本地存储的 PDF/PDF。

问题是,每当我放置 ScrollView (水平或垂直)时,当我尝试转到包含该 View 的 Activity 时,我的应用程序就会崩溃。

目前,所述 Activity 如下所示:

完整的 xml 代码:

<android.support.constraint.ConstraintLayout 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:id="@+id/ConstraintLayout">

<HorizontalScrollView
android:layout_width="368dp"
android:layout_height="495dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="horizontal">

<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/generatieve_tros" />

<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
app:srcCompat="@drawable/botrytis" />
</LinearLayout>

</HorizontalScrollView>
</android.support.constraint.ConstraintLayout>

错误:

D/ViewRootImpl@73c34ee[activity_kop]: MSG_WINDOW_FOCUS_CHANGED 0
D/ViewRootImpl@73c34ee[activity_kop]: dispatchDetachedFromWindow
D/InputTransport: Input channel destroyed: fd=80
D/ViewRootImpl@8980143[activity_tree]: ViewPostImeInputStage processPointer 0
D/ViewRootImpl@8980143[activity_tree]: ViewPostImeInputStage processPointer 1
D/ViewRootImpl@8980143[activity_tree]: MSG_WINDOW_FOCUS_CHANGED 0
D/TextView: setTypeface with style : 0
D/TextView: setTypeface with style : 0
I/art: Starting a blocking GC Alloc
I/art: Starting a blocking GC Alloc
I/art: Starting a blocking GC Alloc
I/art: Alloc partial concurrent mark sweep GC freed 86(3KB) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 153us total 9.255ms
I/art: Starting a blocking GC Alloc
I/art: Alloc concurrent mark sweep GC freed 31(944B) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 135us total
14.916ms
I/art: Forcing collection of SoftReferences for 126MB allocation
I/art: Starting a blocking GC Alloc
I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 143us total
13.015ms
W/art: Throwing OutOfMemoryError "Failed to allocate a 132710412 byte allocation with 16772392 free bytes and 113MB until OOM"
I/art: Starting a blocking GC Alloc
I/art: Starting a blocking GC Alloc
I/art: Starting a blocking GC Alloc
I/art: Alloc partial concurrent mark sweep GC freed 6(144B) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 146us total 8.006ms
I/art: Starting a blocking GC Alloc
I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 152us total
13.678ms
I/art: Forcing collection of SoftReferences for 126MB allocation
I/art: Starting a blocking GC Alloc
I/art: Alloc concurrent mark sweep GC freed 3(72B) AllocSpace objects, 0(0B) LOS objects, 10% free, 142MB/158MB, paused 147us total
12.795ms
W/art: Throwing OutOfMemoryError "Failed to allocate a 132710412 byte allocation with 16776400 free bytes and 113MB until OOM"
D/skia: --- allocation failed for scaled bitmap
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
Process: eu.app.app, PID: 8423
java.lang.OutOfMemoryError: Failed to allocate a 132710412 byte allocation with 16776400 free bytes and 113MB until OOM
at dalvik.system.VMRuntime.newNonMovableArray(Native Method)
at android.graphics.BitmapFactory.nativeDecodeAsset(Native Method)
at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:700)
at android.graphics.BitmapFactory.decodeResourceStream(BitmapFactory.java:535)
at android.graphics.drawable.Drawable.createFromResourceStream(Drawable.java:1179)
at android.content.res.ResourcesImpl.loadDrawableForCookie(ResourcesImpl.java:770)
at android.content.res.ResourcesImpl.loadDrawable(ResourcesImpl.java:621)
at android.content.res.Resources.getDrawable(Resources.java:1640)
at android.content.Context.getDrawable(Context.java:525)
at android.support.v4.content.ContextCompat.getDrawable(ContextCompat.java:351)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:200)
at android.support.v7.widget.AppCompatDrawableManager.getDrawable(AppCompatDrawableManager.java:188)
at android.support.v7.content.res.AppCompatResources.getDrawable(AppCompatResources.java:100)
at android.support.v7.widget.AppCompatImageHelper.loadFromAttributes(AppCompatImageHelper.java:58)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:78)
at android.support.v7.widget.AppCompatImageView.<init>(AppCompatImageView.java:68)
at android.support.v7.app.AppCompatViewInflater.createView(AppCompatViewInflater.java:106)
at android.support.v7.app.AppCompatDelegateImplV9.createView(AppCompatDelegateImplV9.java:1024)
at android.support.v7.app.AppCompatDelegateImplV9.onCreateView(AppCompatDelegateImplV9.java:1081)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:776)
at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:734)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:865)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.rInflate(LayoutInflater.java:873)
at android.view.LayoutInflater.rInflateChildren(LayoutInflater.java:828)
at android.view.LayoutInflater.inflate(LayoutInflater.java:525)
at android.view.LayoutInflater.inflate(LayoutInflater.java:427)
at android.view.LayoutInflater.inflate(LayoutInflater.java:378)
at android.support.v7.app.AppCompatDelegateImplV9.setContentView(AppCompatDelegateImplV9.java:287)
at android.support.v7.app.AppCompatActivity.setContentView(AppCompatActivity.java:139)
at eu.app.app.activity_fruit.onCreate(activity_fruit.java:12)
at android.app.Activity.performCreate(Activity.java:6912)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1126)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2877)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2985)
at android.app.ActivityThread.-wrap14(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1635)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6692)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1468)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1358) Application terminated.

最佳答案

您尝试加载的图像太大,导致内存不足异常。尝试使用像 Glide 这样的图像加载器像这样向下采样并将图像加载到 ImageView 中,

Glide.with(context)
.load(R.drawable.image)
.apply(new RequestOptions().override(100,100)/*down sample*/)
.into(new SimpleTarget<Drawable>() {
@Override
public void onResourceReady(Drawable resource, Transition<? super Drawable> transition) {
//load the image into image view
}
});

关于java - 水平 ScrollView 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48219074/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com