0
我遇到這樣的問題:當您嘗試將ImageView添加到LinearLayout時,某些圖像未加載,程序以黑屏停止。圖片JPG或PNG沒有區別。試圖將100x100px的大小更改爲1080x1920。如果我將圖片替換爲另一張圖片,那麼一切都很好,但我需要這張圖片。我把這個例外放到這個代碼中,但是在logcat中沒有任何東西,即不會發生異常。 請幫幫我。謝謝。添加ImageView導致黑屏
for (int i = 0, lenI = anims.length; i < lenI; i++) {
try {
LinearLayout linearLayout = new LinearLayout(this);
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
//add image
ImageView imageView = new ImageView(this);
linearLayout.addView(imageView);
int resId = getResources().getIdentifier("ru.romston.testprog:drawable/"+pics[i], null, null);
imageView.setImageResource(resId);
imageView.setMaxHeight(100);
imageView.setMaxWidth(100);
imageView.setPadding(5,5,5,5);
imageView.setAdjustViewBounds(true);
//label
TextView textView = new TextView(this);
linearLayout.addView(textView);
textView.setText(anims[i]);
layout.addView(linearLayout);
} catch (Exception e) {
Log.e(TAG, "read data: error!" + e.getMessage(), e);
}
}
沒有幫助。壞圖片:420x420px 72dpi。好圖片:538x538px 96dpi。將圖像大小設置爲50x50 - 確定!這對我沒有好處。 – romston
我找到了原因。在Android 2.3.3上沒有問題。在4.x的問題是。主線程中禁止使用繁重進程的東西。沒有例外,這很糟糕。這有助於更快地解決問題。 – romston