我有一个包含图像(每行)的 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;
}
}
在下一个 Activity 中,我使用相同的代码并看到图像。
width = getWindowManager().getDefaultDisplay().getWidth();
double a = (double) 44/96;
Img.getLayoutParams().height = (int) (a*width);
我认为设备内存不够大,无法显示所有图像
这是日志
eglSurfaceAttrib not implemented
Dropping event due to no 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 event due to no 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, paused 6ms, total 6ms
最佳答案
我认为设备内存不足或类似情况。 我已将照片设置为在后台加载,现在一切正常。
关于android - 某些设备上的 ImageView 黑色背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31592939/