在一些设备上的ImageView黑色背景

时间:2015-07-23 16:21:36

标签: android listview imageview

我有一个包含图像的ListView(每行),每个图像的宽度为match_parent,高度约为宽度的0.4。

现在一切正常,除了大屏幕设备(如nexus 7 ......),而不是我看到黑色背景的图像

这是我的ListView适配器

public class Adapter extends ArrayAdapter<String>{
    int width = 0;

    private final Activity context;
    private final String[] title;
    private final int[] img;

    public PlansAdapter(Activity context,
                        String[] title, int[] img) {
        super(context, R.layout.listsingle, title);
        this.context = context;
        this.title = title;
        this.img = img;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        LayoutInflater inflater = context.getLayoutInflater();
        convertView = inflater.inflate(R.layout.listsingle, null, true);
        TextView Title = (TextView) convertView.findViewById(R.id.text);
        Title.setText(title[position]);
        ImageView Img = (ImageView) convertView.findViewById(R.id.img);
        Img.setImageResource(img[position]);
        width = ((Activity) getContext()).getWindowManager().getDefaultDisplay().getWidth();
        double a = (double) 44/96;

        Img.getLayoutParams().height = (int) (a*width);

        RelativeLayout bghover = (RelativeLayout )convertView.findViewById(R.id.bghover);
        bghover.getLayoutParams().height = (int) (a*width);


        return convertView;
    }
}

在下一个活动中,我使用相同的代码,然后看到图像。

width = getWindowManager().getDefaultDisplay().getWidth();
double a = (double) 44/96;
Img.getLayoutParams().height = (int) (a*width);

我认为设备内存不足以显示所有图像

这是logcat

  

eglSurfaceAttrib未实施

     

由于没有窗口焦点而丢弃事件:KeyEvent {action = ACTION_DOWN,   keyCode = KEYCODE_ALT_RIGHT,scanCode = 100,   metaState = META_ALT_ON | META_ALT_RIGHT_ON,flags = 0x8,repeatCount = 497,   eventTime = 242910,downTime = 216396,deviceId = 1,source = 0x301}

     

由于没有窗口焦点而丢弃事件:KeyEvent {action = ACTION_DOWN,   keyCode = KEYCODE_ALT_RIGHT,scanCode = 100,   metaState = META_ALT_ON | META_ALT_RIGHT_ON,flags = 0x8,repeatCount = 498,   eventTime = 242960,downTime = 216396,deviceId = 1,source = 0x301}

     

GC_FOR_ALLOC释放1461K,8%免费18275K / 19844K,暂停6ms,总计6ms

1 个答案:

答案 0 :(得分:0)

我认为设备耗尽了内存或类似的东西。 我已经将照片加载到背景中,现在一切正常。