0

I have an AppWidget RemoteView with a ListView that holds one child - ImageView with custom font text.

Here is my code:

Typeface tf = Typeface.createFromAsset(mContext.getAssets(),"fonts/myfont.ttf");

TextPaint textPaint = new TextPaint(TextPaint.ANTI_ALIAS_FLAG);
textPaint.setTypeface(tf);
textPaint.setStyle(Paint.Style.FILL);
textPaint.setColor(mycolor);
textPaint.setTextSize(px);

StaticLayout staticLayout = new StaticLayout(textString, textPaint, width, Layout.Alignment.ALIGN_NORMAL, 1.0f, 0.0f, false);

Bitmap bitmap = Bitmap.createBitmap(width, staticLayout.getHeight(), Bitmap.Config.ARGB_8888);

Canvas canvas = new Canvas(bitmap);
staticLayout.draw(canvas);

rv.setImageViewBitmap(R.id.imageViewText, bitmap);

It works correctly. But, every time the text is long enough to exceed 50 / 60 lines, it shows as empty, but i can scroll the listview (so the staticLayout is not empty, because the bitmap's height is not 0).

Another important thing is the following behavior: When i start drag the widget, the text appears. Immediately after i drop it, the text disappears again.

What can cause that kind of behavior? Maybe someone faced similar problem can help.

EDIT:

I tried to save the bitmap as png to the cache directory, then set the image via setImageViewUri method, but the result is the same. Transparent image with the right dimensions, and when drag and drop - its visible.

J.Doe
  • 326
  • 2
  • 14
  • Perhaps the bitmap is too large. – CommonsWare Jul 23 '17 at 20:37
  • it displays the whole bitmap height, but the text is invisible. – J.Doe Jul 23 '17 at 20:38
  • My point is that the home screen may be having problems with images of that size (resolution or memory). Please bear in mind that there are *hundreds* of different home screen implementations. The more you push the limits, the more likely it is that your app widget will fail on some of those home screens. Moreover, if the content is divided into lines, why not have one image per line? – CommonsWare Jul 23 '17 at 20:43
  • Its a nice idea, thank you. I agree, maybe the bitmap too large, but i thought if its too large it will cause OutOfMemory exception at least. – J.Doe Jul 23 '17 at 20:46
  • Ok, it happens because of image size. I found other similar issue https://stackoverflow.com/questions/16727858/android-widget-with-imageview-is-invisible-until-i-start-moving-it – J.Doe Jul 24 '17 at 09:38

0 Answers0