我尝试使用Glide在Recyclerview中显示图像,但它们模糊不清(图像采用jpg格式)。
我尝试过使用Picasso来展示它们但我得到了完全相同的问题:图像模糊不清。作为测试,我也有10个drawables,这些似乎显示得很好。有谁知道为什么图像模糊了?
**编辑**
我刚刚在(Genymotion模拟器)Google Galaxy Nexus 4.2.2上运行了我的代码; API 17和图像都很好!所以下一个问题是为什么图像在(Genymotion模拟器)摩托罗拉Moto X 4.3上模糊了; API 18。
**编辑**
我想我已经发现为什么我的图像模糊了: 在我的主要片段中,我通过自定义内容提供程序将我的图像的URL写入了我的数据库。我的初始图像分辨率较低,因此当我显示它们时,由于调整大小和格式化,它们变得模糊。因此,我使用了更高分辨率的图像,希望能解决这个问题。它最初(沮丧!!),直到我更改了数据库版本号。然后将新图像写入数据库,问题是正确的。
document.getElementById('graphName').textContent
我认为放置我的imageview可能是个好主意:
package demo.example.com.customarrayadapter;
import android.content.Context;
import android.database.Cursor;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;
import com.bumptech.glide.Glide;
import java.util.List;
import demo.example.com.customarrayadapter.data.FlavorsContract;
/**
* Created by richard on 03/01/16.
*/
public class AndroidFlavorCursorRecyclerViewAdapter extends
CursorRecyclerAdapter<AndroidFlavorCursorRecyclerViewAdapter
.DataObjectHolder> {
private static String LOG_TAG = AndroidFlavorCursorRecyclerViewAdapter.class.getSimpleName();
private List<AndroidFlavor> mDataset;
private static MyClickListener myClickListener;
private Cursor mCursor;
private int posterHeight;
private int posterWidth;
public static class DataObjectHolder extends RecyclerView.ViewHolder
implements View
.OnClickListener {
TextView label;
ImageView image;
public DataObjectHolder(View itemView) {
super(itemView);
//label = (TextView) itemView.findViewById(R.id.flavor_text);
image = (ImageView) itemView.findViewById(R.id.flavor_image);
Log.i(LOG_TAG, "Adding Listener");
itemView.setOnClickListener(this);
}
@Override
public void onClick(View v) {
myClickListener.onItemClick(getPosition(), v);
}
}
public void setOnItemClickListener(MyClickListener myClickListener) {
this.myClickListener = myClickListener;
}
public AndroidFlavorCursorRecyclerViewAdapter(Cursor cursor, int w, int h) {
super(cursor);
//mCursor = cursor;
posterHeight = h;
posterWidth = w;
}
@Override
public DataObjectHolder onCreateViewHolder(ViewGroup parent,
int viewType) {
View view = LayoutInflater.from(parent.getContext())
.inflate(R.layout.flavor_item, parent, false);
DataObjectHolder dataObjectHolder = new DataObjectHolder(view);
return dataObjectHolder;
}
@Override
public void onBindViewHolderCursor(DataObjectHolder holder, Cursor cursor) {
Context context = holder.image.getContext();
//Log.i(LOG_TAG,"image:" + cursor.getString(
// cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_FILM_POSTER)));
//holder.label.setText(cursor.getString(
// cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_VERSION_NAME)));
String url = cursor.getString(
cursor.getColumnIndex(FlavorsContract.FlavorEntry.COLUMN_FILM_POSTER));
Glide.with(context.getApplicationContext()).load(url)
.into(holder.image);
//Picasso.with(context).load("http://i.imgur.com/DvpvklR.png")
// .into(holder.image);
Log.v(LOG_TAG, "onBindViewHolderCursor() " + cursor.getCount());
}
// public void addItem(AndroidFlavor dataObj, int index) {
// mDataset.add(dataObj);
// notifyItemInserted(index);
//}
//public void deleteItem(int index) {
// mDataset.remove(index);
// notifyItemRemoved(index);
//}
//@Override
//public int getItemCount() {
// return mDataset.size();
//}
public interface MyClickListener {
public void onItemClick(int position, View v);
}
}
SquareImageView类:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<demo.example.com.customarrayadapter.SquareImageView
android:id="@+id/flavor_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:scaleType="centerCrop"
/>
</FrameLayout>
答案 0 :(得分:0)
您的问题很明确,但您是否只尝试过这些模拟器? 为什么我没有找到.size()无处可寻?
你确定你的照片已经调整大小并且没有形成只是为了完全看到吗?
如果是,请尝试查看您的控制台。你看到这样的错误吗?
W/OpenGLRenderer: Bitmap too large to be uploaded into a texture
答案 1 :(得分:0)
myFault!我的.override!
加载完图片后,请确保图片已正确调整大小,然后再将其发送到版面广告容器中:
public Bitmap loadFormattedImage(Context c ,int imv_icone){
Glide.with(c)
.load(imv_icone)
.diskCacheStrategy(DiskCacheStrategy.ALL)
.override(300, 200);
return BitmapFactory.decodeResource(c.getResources(), imv_icone);
}
你已经尝试过这个吗?