Listview增加所选索引的大小

时间:2014-04-03 11:17:45

标签: android android-listview

你好我遇到listview的问题。我想在listview中扩展所选图像的大小,例如我有一个listivew,当我点击一个项目时,它的大小比listview中的其他行增加了我的onitemclick listner的示例代码是

    @Override
public void onItemClick(AdapterView<?> parent, View view, int position,
        long id) {

    if(civ!=null){

        civ.setVisibility(View.VISIBLE);
    }




     civ = (CustomImageView)view.findViewById(R.id.civ_shelfBook_BookImage);
     LayoutParams params = (LayoutParams) civ.getLayoutParams();

        params.height = 0;
        params.width = 0;
        civ.setLayoutParams(params);

     updateView(position);

    DetailActivity.shelfID = civ.getShelfID();
    DetailActivity.currentlySelected =position;



}

1 个答案:

答案 0 :(得分:2)

创建自定义列表视图适配器并在getView方法中执行以下操作:

public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder;

    if(convertView == null) {
        holder = new ViewHolder();
        convertView = mLayoutInflater.inflate(R.layout.my_layout, parent, false);

        holder.image = (ImageView)convertView.findViewById(R.id.image);
        convertView.setTag(holder);
    } else {
         holder = (ViewHolder) convertView.getTag(); 
    }

    holder.image.setImageResource(R.drawable.image));

    if(position == selectedPosition) {  
        convertView.setLayoutParams(MATCH_PARENT);// Set value as required
      // Change row and image size here

    } else {
        convertView.setLayoutParams(WRAP_CONTENT);
    }

    return convertView;
}

private static class ViewHolder {
   ImageView image;
}