【发布时间】:2015-11-27 10:34:50
【问题描述】:
我正在使用 ViewFlipper,我的 viewFlipper 工作正常,直到我增加了图片的高度。
它给了我 OutOfMemoryError。
这是包含 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);
}
}
我没有使用位图。
当我删除按钮时,viewFlipper 可以正常工作,但是当我将这 4 个按钮放在脚蹼下方时,它不起作用,并且会因 OutOfMemoryError 而关闭。
我该怎么办?
【问题讨论】:
-
您的布局不太可能导致 OOM 错误。这很可能是由您未发布的代码引起的。您还应该发布堆栈跟踪,否则任何人都只能猜测。另请参阅stackoverflow.com/help/how-to-ask
-
简单的解决方案:在清单上使用 LargeHeap。
标签: android out-of-memory slideshow viewflipper