【发布时间】:2016-12-23 01:31:38
【问题描述】:
我在RecyclerView 中显示图像,其来源是从彩信中获取的位图。问题是图像没有显示。绝对没有任何显示。这是我的 onBindView:
@Override
public void onBindViewHolder(ViewHolder holder, int position) {
// - get element from your dataset at this position
// - replace the contents of the view with that element
final String name = mDataset.get(position).getContact() ;
final MMSMessage message = mDataset.get(position);
holder.txtHeader.setText(name);
DateTime dateTime = new DateTime(message.getDate());
holder.txtDate.setText(dateTime.toString(Globals.generalSQLFormatterDT));
holder.txtText.setText(message.getBody());
holder.txtText.setVisibility(View.VISIBLE);
Bitmap bitmap = message.getBitmap();
if (bitmap != null) {
//bitmap is not null and I can see an image using Android Studio
bitmap =Bitmap.createScaledBitmap(bitmap, 120, 120, false);
holder.imgMMS.setImageBitmap(bitmap);
} else {
holder.imgMMS.setVisibility(View.GONE);
}
}
ImageView 的 xml:
<ImageView
android:layout_below="@+id/thirdLine"
android:id="@+id/imageMMS"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginRight="6dip"
android:contentDescription="TODO"
/>
我查看了here 并尝试将图像缩小到任意小尺寸。我认为这不是内存不足错误 - 我尝试将启动器图标放入作为测试。我做错了什么?
【问题讨论】:
-
为什么在
if中没有针对else的操作? -
@Selvin 不确定你的意思?
-
else中只有一个“动作”...if中的相反动作在哪里...我想为每个类似的问题获得一分钱...