开发者社区 问答 正文

关于Listview加载图片错位的问题

我用得是Xutils 然后有的item有图片有的不显示,结果错位了

下面代码:

 //图片url
    public View getView(final int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub

         final ViewHolder holder;
        if (convertView == null) {
                          holder = new ViewHolder();
            convertView = View.inflate(getApplicationContext(), R.layout.shequlistadaper, null);


holder.shequtupian1 = (ImageView) convertView.findViewById(R.id.shequtupian1);

holder.shequtupian2 =(ImageView) convertView.findViewById(R.id.shequtupian2);

holder.shequtupian3 = (ImageView) convertView.findViewById}
 else {
 holder = (ViewHolder) convertView.getTag();
 }
 //图片url
 String p1 =tupian1.get(position).toString();
 String p2 =tupian2.get(position).toString();
 String p3 =tupian3.get(position).toString();
 //加载图片
 if(p1.equals("no")){
 utils1.display(holder.shequtupian1, p1);
 holder.shequtupian1.setVisibility(View.GONE); 
        }else{

             holder.shequtupian1.setVisibility(View.VISIBLE);
               utils1.display(holder.shequtupian1, p1);}

展开
收起
爵霸 2016-03-12 09:18:25 2022 分享 版权
1 条回答
写回答
取消 提交回答
  • 你有把viewholder 作为tag设置到convertview上去么?代码里没看到。而且最好给holder添加一个可以唯一辨识的tag,比如position

    2019-07-17 19:00:03
    赞同 展开评论
问答地址: