ImageView black background on some devices

I have a ListView that contains images (each row), the width of each image matches the match_parent and the height is about 0.4 times the width.

Everything works fine now except for large screen devices (like nexus 7 ...) instead of images I see on black background

Here is my ListView adapter

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;
    }
}

      

In the next activity, I am using the same code and I can see the image.

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

      

I think the device memory is not large enough to show all images

Here is the logcat

eglSurfaceAttrib not implemented

Dropping an event due to lack of window focus: 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}

Dropping an event due to lack of window focus: 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 freed 1461K, 8% free 18275K / 19844K, suspended 6ms, total 6ms

+3


source to share


1 answer


I think the device is running out of memory or something. I took photos to upload in the background and now everything works fine.



0


source







All Articles