0

我有一个AppWidget RemoteView带有ListView一个孩子ImageView的带有自定义字体文本的。

这是我的代码:

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

它工作正常。但是,每次文本长到超过 50 / 60 行时,它都会显示为空,但我可以滚动列表视图(因此 staticLayout 不为空,因为位图的高度不为 0)。

另一个重要的事情是以下行为:当我开始拖动小部件时,会出现文本。在我放下它后,文本再次消失。

什么会导致这种行为?也许遇到类似问题的人可以提供帮助。

编辑:

我尝试将位图作为png保存到缓存目录,然后通过setImageViewUri方法设置图像,但结果是一样的。具有正确尺寸的透明图像,并且在拖放时 - 它是可见的。

4

0 回答 0