私はrecyclerviewに小さな(60x60)アルバムアートビットマップを設定したいと思っています。私は、私が知っていたすべてを試した、助けてください。decodeStreamにrecyclerViewにビットマップイメージを設定しない
私は画像を縮小するために使用しているコード:
public static int calculateSize(BitmapFactory.Options opt, int reqHeight, int reqWidth){
int height = opt.outHeight;
int width = opt.outWidth;
int inSampleSize = 1;
if(height > reqHeight || width > reqWidth){
final int halfWidth = width/2;
final int halfHeight = height /2;
while((halfHeight/inSampleSize) >= reqHeight && (halfWidth/inSampleSize) >= reqWidth){
inSampleSize *= 2;
}
}
return inSampleSize;
}
public Bitmap decodeSampleBitmapFromArray(InputStream stream, Rect rect, int reqHeight, int reqWidth){
BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
Bitmap bit = BitmapFactory.decodeStream(stream, rect, options);
//Calculate sample size
options.inSampleSize = calculateSize(options, reqHeight, reqWidth);
//Decode bitmap with insamplesize set false
options.inJustDecodeBounds = false;
return bit;
}
それから私は私のrecyclerviewアダプタを移入するために、私のonCreateメソッドでdecodeSampleBitmapFromArray関数を呼び出し:
@Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
...
adapter = new CustomRecycler(paths);
recyclerView = (RecyclerView)v.findViewById(R.id.ryc);
lManager = new LinearLayoutManager(getActivity());
recyclerView.setLayoutManager(lManager);
recyclerView.setHasFixedSize(true);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
metaRetriever.setDataSource(path);
byte[] b = metaRetriever.getEmbeddedPicture();
if (b != null) {
InputStream in = new ByteArrayInputStream(b);
paths.add(decodeSampleBitmapFromArray(in,new Rect(-1,-1,1,1), 60, 60));
}else{
Bitmap altIcon = BitmapFactory.decodeResource(getResources(), R.drawable.beat);
paths.add(altIcon);
}
}
マイRecyclerAdapterその後、 ImageViewを使用してビットマップを受信して表示します。
holder.artImage.setImageBitmap(mImage.get(position));
このすべてをやっていると、画像はまだrecyclerviewに移入されていません。私は何をしているのですか?事前に感謝します
CustomRecyclerは空のパスのみを認識しています...コンテンツが変更されたことを通知していません – Selvin
私のプロジェクトではこれを持っていますが、このコードを投稿すると間違って削除されました。 – DevMike
*画像にまだrecyclerviewが設定されていない*誤解を招く...少なくともプレースホルダがないか、画像がロードされていないかどうかを推測するのは難しい...また、少なくとも一部のデバッグコードは表示されない"bitmap is null"メッセージ) – Selvin