我想把看门人放在cardvIEw里面.可以吗还是应该尝试别的东西?
我用VIEwPager做了,但看起来太慢了.这是查看器适配器的一部分.
@OverrIDepublic Object instantiateItem(VIEwGroup collection,int position) { LayoutInflater inflater = LayoutInflater.from(mContext); VIEwGroup layout = (VIEwGroup) inflater.inflate(R.layout.vIEwpager_custom,collection,false); collection.addVIEw(layout); ImageVIEw image = (ImageVIEw) layout.findVIEwByID(R.ID.vIEwPagerImageVIEw); image.setimageResource(mPics[position]); return layout;}解决方法 你要走正确的路.
只需要加载压缩位图,而不是未压缩的位图.
您直接将位图资源设置为您的图像视图.使用像毕加索的图书馆
https://github.com/square/picasso/
或使用谷歌的官方来源有效地加载大型位图.
首先在您的活动中复制此方法:
public static int calculateInSampleSize( BitmapFactory.Options options,int reqWIDth,int reqHeight) { // Raw height and wIDth of image final int height = options.outHeight; final int wIDth = options.outWIDth; int inSampleSize = 1; if (height > reqHeight || wIDth > reqWIDth) { final int halfheight = height / 2; final int halfWIDth = wIDth / 2; // Calculate the largest inSampleSize value that is a power of 2 and keeps both // height and wIDth larger than the requested height and wIDth. while ((halfheight / inSampleSize) > reqHeight && (halfWIDth / inSampleSize) > reqWIDth) { inSampleSize *= 2; } } return inSampleSize;}
那么这个方法来解码位图:
public static Bitmap decodeSampledBitmapFromresource(Resources res,int resID,int reqHeight) { // First decode with inJustDecodeBounds=true to check dimensions final BitmapFactory.Options options = new BitmapFactory.Options(); options.inJustDecodeBounds = true; BitmapFactory.decodeResource(res,resID,options); // Calculate inSampleSize options.inSampleSize = calculateInSampleSize(options,reqWIDth,reqHeight); // Decode bitmap with inSampleSize set options.inJustDecodeBounds = false; return BitmapFactory.decodeResource(res,options);}
然后加载你的位图像这样:
@OverrIDepublic Object instantiateItem(VIEwGroup collection,false); collection.addVIEw(layout); ImageVIEw image = (ImageVIEw) layout.findVIEwByID(R.ID.vIEwPagerImageVIEw); image.setimageBitmap( decodeSampledBitmapFromresource(getResources(),R.ID.myimage,reqwIDth,reqheight)); return layout;}总结
以上是内存溢出为你收集整理的android – 在回收者的cardview里做滑动图像的最好方法是什么?全部内容,希望文章能够帮你解决android – 在回收者的cardview里做滑动图像的最好方法是什么?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)