Android ViewFlipper OutOfMemoryError

Android ViewFlipper OutOfMemoryError,android,out-of-memory,slideshow,viewflipper,Android,Out Of Memory,Slideshow,Viewflipper,我正在使用ViewFlipper,我的ViewFlipper工作正常,直到我增加了图片的高度 这给了我一个记忆错误 以下是包含viewFlipper的活动的XML代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" andr

我正在使用ViewFlipper,我的ViewFlipper工作正常,直到我增加了图片的高度

这给了我一个记忆错误

以下是包含viewFlipper的活动的XML代码:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.taktaz.activities.OneProductActivity"
>
<ViewFlipper
    android:id="@+id/flipper1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="450px"
    android:clipChildren="true"
    android:autoStart="true"
    android:flipInterval="4000"
    android:inAnimation="@anim/right_in"
    android:outAnimation="@anim/left_out"
    android:layout_alignParentTop="true"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentStart="true">


</ViewFlipper>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="100dp"
    android:orientation="vertical"
    android:layout_alignParentBottom="true"
    android:layout_margin="4dp"
    >
    <Button
        android:id="@+id/btn_productDetails"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_product_specifics_style"
        android:layout_marginBottom="1dp"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/btn_productCatalog"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_product_catalog_style"
        android:layout_marginBottom="1dp"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/btn_productManual"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_product_manual_style"
        android:layout_marginBottom="1dp"
        android:layout_weight="1"/>
    <Button
        android:id="@+id/btn_productWebsite"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/btn_product_website_style"
        android:layout_marginBottom="1dp"
        android:layout_weight="1"
        />
</LinearLayout>

在这里,我设置了viewFlipper ImageResources:

 private void setUpFlipper() {
    TypedArray imgResource = getResources().obtainTypedArray(R.array.hayabusa_imgs);
    mFlipper = (ViewFlipper) findViewById(R.id.flipper1);

    for (int i = 0 ; i < imgResource.length() ; i++)
    {
        ImageView imageView = new ImageView(this);
        imageView.setImageResource(imgResource.getResourceId(i,-1));
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        imageView.setAdjustViewBounds(true);
        mFlipper.addView(imageView);
    }
}
private void setUpFlipper(){
TypedArray imgResource=getResources().obtainTypedArray(R.array.hayabusa_imgs);
mFlipper=(ViewFlipper)findViewById(R.id.flipper1);
for(int i=0;i
我没有使用位图

当我移除按钮时,viewFlipper可以正常工作,但当我将这4个按钮放在flipper下方时,它将无法工作,并将以OutOfMemoryError关闭


我该怎么办?

安卓系统中图像的常见问题是:

您使用android limit,这就是您看到此错误的原因。重新缩放图像,不要以原始大小显示它们

ViewFlipper加载内存中的所有视图。将所有图像加载到内存中是个坏主意。 看看下面的问题

由于不推荐使用Gallery,请使用ViewPager。支持库中提供了ViewPager。您还可以配置应向前和向后加载的视图数量。您可以按需加载图像,也可以销毁它们,只要它们当前不需要。它允许您重用视图并在内存中仅加载几个视图:

在这里,您可以找到一些很好的示例来实现它:

您的布局不太可能导致OOM错误。这很可能是由您未发布的代码引起的。您还应该发布堆栈跟踪,否则任何人都只能猜测。另外,请参阅简易解决方案:在清单上使用LargeHeap。ViewPager从何而来???@Kuffs您是对的,对不起。我把viewflipper和viewpager搞混了。但是我没有使用位图。我还想至少以600*420的尺寸显示图像(我已经将图像尺寸设置为这个宽度和高度)。我还缩小了每个图像的大小,每个图像约为70KB。@Ali_kabir我已经更新了我的答案。希望能有帮助。