局部存储的图像未在回收道内的卡片视图中显示



我有一个 RecyclerView,其 CardView是其列表项目。CardView只有2个TextView和一个ImageView

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="70dp"
    android:layout_marginTop="2dp"
    android:layout_marginBottom="2dp"
    android:id="@+id/dcCardView">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="horizontal"
        android:background="@drawable/detail_coast_cardview_bg">
        <ImageView
            android:id="@+id/dcImage"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_marginStart="8dp"
            android:src="@drawable/radiation"
            android:layout_gravity="center_vertical" />
        <LinearLayout
            android:layout_gravity="center_vertical"
            android:layout_marginStart="16dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical">
        <TextView
            android:id="@+id/dcName"
            android:textColor="#fff"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="212"
            android:textSize="18dp" />
        <TextView
            android:textColor="#fff"
            android:id="@+id/dcValue"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="renu asdasasd"
            android:textSize="18dp" />
        </LinearLayout>
    </LinearLayout>
</android.support.v7.widget.CardView>

上课的类是这个

public class DetailedCoastRecyclerView {
    //region fields
    private String name;
    private String value;
    private int imageName;
    //end region fields
    //constructor
    public DetailedCoastRecyclerView() {}
    public DetailedCoastRecyclerView(String name, String value, int image) {
        this.name = name;
        this.value = value;
        this.imageName = image;
    }
    public String getName() {
        return name;
    }
    public String getValue() {
        return value;
    }
    public int getImageName() {
        return imageName;
    }
}

和我的CoastDetailsActivity2

public class CoastDetailsActivity2 extends AppCompatActivity {
    private Context context;
    private SharedPreferences sharedPreferences;
    private SharedPreferences.Editor editor;
    private int coastId;
    private String jsonCoastDetailsString = "";
    private RecyclerView recyclerView;
    private DetailedCoastAdapter detailedCoastAdapter;
    private ImageView btnBlueFlag;
    private ImageView btnHandycapFriendly;
    private ImageView btnFavorite;
    private ImageView btnWaze;
    private LinearLayout mainLayout;
    private Beach mBeach;
    private TextView tvBeachName;
    private DetailedCoastWithForcast detailedCoastWithForcast;
    private DetailedBeachMetadata detailedBeachMetadata;
    private DetailedBeachHourlyForecast dbhfToday;
    private List<DetailedCoastRecyclerView> detailedCoastRecyclerViewList = new ArrayList<>();
    private Map<String, String> windBearing = new HashMap<>();
    private Map<String, String> jellyType = new HashMap<>();
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_coast_details2);
        setPointer();
    }
    private void setPointer() {
        this.context = this;
        mainLayout = (LinearLayout) findViewById(R.id.mainLayout);
        sharedPreferences = context.getSharedPreferences(sharedPreferencesName, MODE_PRIVATE);
        editor = sharedPreferences.edit();
        tvBeachName = (TextView) findViewById(R.id.tvBeachName);
        //start the forecast activity
        tvBeachName.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(context, ForecastActivity.class);
                intent.putExtra("coastId", coastId);
                startActivity(intent);
            }
        });
        AndroidNetworking.initialize(context);
        //get the coastId
        Bundle extras = getIntent().getExtras();
        if (extras == null) {
            //TODO add snackbar for error
        } else {
            coastId = extras.getInt("coastId");
        }
        getBeachDetails();
        recyclerView = (RecyclerView) findViewById(R.id.dcRecyclerView);
        detailedCoastAdapter = new DetailedCoastAdapter(detailedCoastRecyclerViewList, context);
        RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setItemAnimator(new DefaultItemAnimator());
        recyclerView.setAdapter(detailedCoastAdapter);
    }
}

和适配器

public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.myViewHolder> {
    Context context;
    private List<DetailedCoastRecyclerView> dbhf0;
    public ForecastAdapter(Context context, List<DetailedCoastRecyclerView> dbhf0) {
        this.context = context;
        this.dbhf0 = dbhf0;
    }
    @Override
    public myViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(context).inflate(R.layout.detailed_coast_card, parent, false);
        return new myViewHolder(view);
    }
    @Override
    public void onBindViewHolder(myViewHolder holder, int position) {
        DetailedCoastRecyclerView dcrv = dbhf0.get(position);
        holder.tvName.setText(dcrv.getName());
        holder.tvValue.setText(dcrv.getValue());
        //holder.ivImage.setImageResource(dcrv.getImageName());
        Glide.with(context).load(dcrv.getImageName()).into(holder.ivImage);
    }
    @Override
    public int getItemCount() {
        return dbhf0.size();
    }
    public class myViewHolder extends RecyclerView.ViewHolder {
        ImageView ivImage;
        TextView tvName;
        TextView tvValue;
        public myViewHolder(View itemView) {
            super(itemView);
            ivImage = (ImageView) itemView.findViewById(R.id.dcImage);
            tvName = (TextView) itemView.findViewById(R.id.dcName);
            tvValue = (TextView) itemView.findViewById(R.id.dcValue);
        }
    }
}

当我运行它时,getBeachDetails()方法从服务器获取所有信息,将其添加到ArrayList并在适配器上调用notifyDataSetChanged()

我知道它的工作正常,因为我看到了每张卡的名称和价值

我在带有3个片段的ViewPager中使用相同的适配器,一切都可以。

有什么想法?

  1. 您提供了预算法的代码,但实际上您正在使用详细的涂料。确保它们是否相同。
  2. 检查您是否在dcrv.getimagename((
  3. 中有有效的URL/资源

我想您的图像分辨率太高,在呈现图像时,Android缓冲区无法处理和引发异常,因此我知道您在将图像质量降低到ImageView上时必须降低图像质量。<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

在毕加索中,这是这样完成的,通过调用resize(width,height)方法。

Picasso.with(context)
    .load(res)
    .resize(width,height)
    .placeholder(placeHolder)
    .into(view);

我猜这是用滑行以相同的方式完成的。

相关内容

  • 没有找到相关文章

最新更新