Android 线性布局库中内存错误-位图大小超出VM预算
当我滚动我的图库的5个元素以上时,我得到了这个内存错误(位图大小超过VM)。这是我应用程序的最后一部分,我非常希望能够完成。 我所有的画廊图片都是180x180。 我读过一些有关StackOverFlow的“内存错误”主题,但大多数都告诉我如何将图像转换为位图,我不知道它是如何工作的。如果有人能为我的问题发布解决方案代码,我将非常感激! 代码如下:Android 线性布局库中内存错误-位图大小超出VM预算,android,gallery,Android,Gallery,当我滚动我的图库的5个元素以上时,我得到了这个内存错误(位图大小超过VM)。这是我应用程序的最后一部分,我非常希望能够完成。 我所有的画廊图片都是180x180。 我读过一些有关StackOverFlow的“内存错误”主题,但大多数都告诉我如何将图像转换为位图,我不知道它是如何工作的。如果有人能为我的问题发布解决方案代码,我将非常感激! 代码如下: public ImageAdapter(Context c) { mContext = c; TypedArray
public ImageAdapter(Context c) {
mContext = c;
TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
a.recycle();
}
public int getCount() {
return mImageIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(final int position, View convertView,ViewGroup parent) {
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater)
mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView=inflater.inflate(R.layout.l1,null);
}
HighscoreManager hm=new HighscoreManager();
hm.addScore(timePerWord);
ImageView imgView = (ImageView)convertView.findViewById(R.id.imageView1);
TextView txtView = (TextView)convertView.findViewById(R.id.textView2);
if(hm.getHighscoreString()[position]!=0)
txtView.setText("\t\t Avg.time: "+hm.getHighscoreString()[position]
);
txtView.setTextSize(20);
imgView.setImageResource(mImageIds[position]);
return convertView;
}
其中.xml文件L1是:(不多,下面是一个图像和一个文本视图)
可能会有所帮助:(如果您只是搜索,也可能会得到许多其他结果)。Gallery小部件也有一个缺陷,使其无法使用回收的视图。我想这对你的记忆问题没有任何帮助。在线搜索EcoGallery,您可以找到修复此漏洞的第三方小部件。它的设置和运行要比股票画廊小部件多一些,虽然我不知道如何在我的代码中实现它,Charlie。我真的不想尝试EcoGallery,我花了很多时间试图让它工作。如果我删除LinearLayout,只让图像出现,效果会很好。但我需要一个文本视图下面的图像以及。请有人找到一个很好的解决方案。可以有另一个选择。不允许用户滑动超过1个画廊图像,但我不知道如何使用它。
<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/l1"
android:layout_width="240dp"
android:layout_height="fill_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="240dp"
android:layout_height="185dp"
android:layout_x="-1dp"
android:layout_y="-15dp"
android:src="@drawable/background" />
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="38dp"
android:layout_x="0dp"
android:layout_y="169dp"
android:text=""
android:gravity="center" />
</AbsoluteLayout>