-1

I have the problem: when you try to add ImageView the LinearLayout, some images are not loaded and the program stops with a black screen. Picture JPG or PNG there is no difference. Tried to change the size of 100x100px to 1080x1920. If I replace the picture on another then everything is fine, but I need this picture. I put the exception to this code, but in the logcat nothing, i.e. the exception does not occur. Please help me. Thank you.

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);
          }
 }
Royston Pinto
  • 6,681
  • 2
  • 28
  • 46
romston
  • 1
  • 1
  • Does this answer your question? [Android : Maximum allowed width & height of bitmap](https://stackoverflow.com/questions/15313807/android-maximum-allowed-width-height-of-bitmap) – Luciano Mar 30 '20 at 05:50

2 Answers2

0

I think the image is of higher resolution/size that Android rendering system fails to scale it into height and width of 100. Try with same image after changing the image size/resolution. Please correct if wrong.

  • Not helped. Bad image: 420x420px 72dpi. Good image: 538x538px 96dpi. Set image size to 50x50 - OK! It`s no good for me. – romston Jul 05 '13 at 13:34
  • I found the reason. On Android 2.3.3 there is no problem. On 4.x problem is. The thing ban on the use of heavy processes in the main thread. It is bad that there is no exception. This helped-would solve problems faster. – romston Jul 06 '13 at 16:00
0

ImageViews have a resolution limit based on OpenGL. If the bitmap or image passes this limit resolution, it shows a black screen and throws no error.

You can retrieve this limit by querying OpenGL:

int[] maxSize = new int[1];
GLES10.glGetIntegerv(GL10.GL_MAX_TEXTURE_SIZE, maxSize, 0);

See this answer for more details

Luciano
  • 1,119
  • 12
  • 18