所以我有一个XML的问题,当我打开它的时候,它会给我力量。当我删除一些图像视图时,假设在XML中总共只有7个图像视图,它是有效的。知道为什么吗?我不知道当我的xml中有更多图像时,它为什么不能工作
App3.XML
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@color/JCBG"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Products"
android:textColor="@color/JCLogo"
android:textSize="30dp"/>
<ViewFlipper
android:id="@+id/fliping"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<!-- The child Views/Layout to flip -->
<!-- Layout 1 for 1st Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical|center_horizontal|center"
android:orientation="vertical" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/gr" />
</LinearLayout>
<!-- Layout 2 for 2nd Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/calvitcdetails" />
</LinearLayout>
<!-- Layout 3 for 3rd Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView3"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/kapedetails"/>
</LinearLayout>
<!-- Layout 4 for 4th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/glutafitdetails"/>
</LinearLayout>
<!-- Layout 5 for 5th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView5"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/pgtdetails"/>
</LinearLayout>
<!-- Layout 6 for 6th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView6"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/hilifedetails"/>
</LinearLayout>
<!-- Layout 7 for 7th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView7"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/organicbarleyjuicedetails"/>
</LinearLayout>
<!-- Layout 8 for 8th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView8"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/barleydetails"/>
</LinearLayout>
<!-- Layout 9 for 9th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView9"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/spirulinadetails"/>
</LinearLayout>
<!-- Layout 10 for 10th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView10"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/omnisoapdetails"/>
</LinearLayout>
<!-- Layout 11 for 11th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView11"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/omnipinkishdetails"/>
</LinearLayout>
<!-- Layout 12 for 12th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView12"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/omnidaydetails"/>
</LinearLayout>
<!-- Layout 13 for 13th Screen -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView13"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="15dp"
android:scaleType="fitXY"
android:src="@drawable/omnitonerdetails"/>
</LinearLayout>
</ViewFlipper>
</LinearLayout>Activity3.java
package com.example.jcw;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.ViewFlipper;
public class activity3 extends Activity
{
private ViewFlipper vf;
private float lastX;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app3);
vf = (ViewFlipper) findViewById(R.id.fliping);
}
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
case MotionEvent.ACTION_DOWN: {
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP: {
float currentX = touchevent.getX();
if (lastX < currentX) {
if (vf.getDisplayedChild() == 0)
break;
vf.setInAnimation(this, R.anim.in_from_left);
vf.setOutAnimation(this, R.anim.out_to_right);
vf.showNext();
}
if (lastX > currentX) {
if (vf.getDisplayedChild() == 1)
break;
vf.setInAnimation(this, R.anim.in_from_right);
vf.setOutAnimation(this, R.anim.out_to_left);
vf.showPrevious();
}
break;
}
}
return false;
}
}发布于 2014-08-23 15:06:46
ImageView小部件使用Bitmaps,这会消耗大量的堆空间。因此,如果您尝试同时加载到多个图像,您将获得OutOfMemoryError,它可能在您的Logcat中。
如果位图分辨率高于实际需要的显示,你可以优化加载他们,here你会发现谷歌的例子如何做到这一点。
如果不是这样,那么你必须以不同的方式设计你的应用程序。
发布于 2014-08-23 15:30:28
在appmanifest: android:largeHeap="true“中添加以下内容
https://stackoverflow.com/questions/25459328
复制相似问题