【问题标题】:GridView shows an Image crop when using custom adapter with long textGridView 在使用带有长文本的自定义适配器时显示图像裁剪
【发布时间】:2015-03-16 09:59:23
【问题描述】:

`公共类 CategoryListAdapter 扩展 BaseAdapter {

private Context context;
ViewHolder holder;
private ArrayList<String> categoryNamesList, categoryIdList;
private final static int selectorsArray[] = { R.drawable.telecom_seletor, R.drawable.airlines_seletor, R.drawable.banking_seletor, R.drawable.dth_selector, R.drawable.electronics_seletor, R.drawable.health_seletor, R.drawable.holidays_seletor, R.drawable.insurance_seletor, R.drawable.shopping_web_seletor, R.drawable.taxi_seletor, R.drawable.food_seletor };

public CategoryListAdapter(Context context, ArrayList<String> categoryNamesList, ArrayList<String> categoryIdList) {
    this.context = context;
    this.categoryNamesList = categoryNamesList;
    this.categoryIdList = categoryIdList;
}

@Override
public int getCount() {
    return categoryNamesList.size();
}

@Override
public Object getItem(int position) {
    return categoryNamesList.get(position);
}

@Override
public long getItemId(int position) {
    return position;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    if (convertView == null) {
        LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
        convertView = mInflater.inflate(R.layout.category_item, null);
        holder = new ViewHolder();
        holder.title = (TextView) convertView.findViewById(R.id.title);
        holder.icon = (ImageView) convertView.findViewById(R.id.img_title);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    holder.title.setText(categoryNamesList.get(position));
    holder.icon.setBackgroundResource(selectorsArray[position % selectorsArray.length]);
    return convertView;
}

} `我使用图像作为图标和文本作为它们的标签,但是当我使用长文本并向下滚动然后向上滚动时,图像图标将被裁剪。 任何建议的家伙。请帮忙。

https://drive.google.com/file/d/0B_2CFh5suxS4bm83OVFqNHRLa1U/view?usp=sharing

https://drive.google.com/file/d/0B_2CFh5suxS4MHdJVktMVkpwXzg/view?usp=sharing

问题图片的链接

【问题讨论】:

  • 用代码 sn-p 解释你的问题
  • 请稍等..我会添加截图..

标签: android gridview android-custom-view custom-adapter


【解决方案1】:

BaseAdapter 类中的getView 应该是这样的:
public View getView(int position, View convertView, ViewGroup parent) { View grid; LayoutInflater inflater = (LayoutInflater) context .getSystemService(Context.LAYOUT_INFLATER_SERVICE); if (convertView == null) { grid = inflater.inflate(R.layout.main_custom_grid, null); } else grid = (View) convertView;

试试imageview.setScaleType(ImageView.ScaleType.FIT_CENTER);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-05
    • 1970-01-01
    • 1970-01-01
    • 2013-04-17
    • 1970-01-01
    相关资源
    最近更新 更多