可绘制的尺寸取决于屏幕尺寸

时间:2015-07-06 12:01:01

标签: android

我正在尝试开发Android应用,并自定义listview,如下所示:

TextView [] CheckBox

现在我想在文本中显示Drawable,但我有图标大小的问题

如何设置Drawable尺寸取决于屏幕尺寸?

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    ViewHolder holder = null;
    Log.v("ConvertView", String.valueOf(position));

    if (convertView == null) {
        LayoutInflater vi = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        convertView = vi.inflate(R.layout.country_info1, null);

        holder = new ViewHolder();
        holder.code = (TextView) convertView.findViewById(R.id.code);
        holder.name = (CheckBox) convertView.findViewById(R.id.checkBox1);
        convertView.setTag(holder);
    } else {
        holder = (ViewHolder) convertView.getTag();
    }

    //display icon of all apps.
    AppList country = appListSelected.get(position);
    try {
        Drawable icon = getApplicationContext().getPackageManager().getApplicationIcon(country.getCode());                  
        icon.setBounds(0, 0, 72, 72);
        holder.code.setCompoundDrawables(icon, null, null, null);
        holder.code.setText("");
    } catch (NameNotFoundException e) {
    }

    holder.name.setText(country.getName());
    holder.name.setChecked(country.isSelected());
    holder.name.setTag(country);

    return convertView;
}

0 个答案:

没有答案
相关问题