问题描述
我在一个活动做到了这一点,它完美的作品。
I have done this in an Activity and it works perfectly.
ImageView myImage = (ImageView) findViewById(R.id.myImageView);
ShapeDrawable mDrawable;
mDrawable = new ShapeDrawable(new OvalShape());
mDrawable.getPaint().setColor(0xff74AC23);
mDrawable.setBounds(x, y, x + width, y + height);
mDrawable.setIntrinsicWidth(width);
mDrawable.setIntrinsicHeight(height);
myImage.setImageDrawable(mDrawable);
现在我想要做同样的事情在一个小部件(内的onUpdate
),我不得不使用 RemoteViews
访问图像。
Now I want to do the same thing in a widget (inside onUpdate
) and I have to use RemoteViews
to access the image.
我怎么叫 setImageDrawable
的的ImageView
从 RemoteViews
?所有远程视图的方法似乎需要位图
。
How do I call the setImageDrawable
of an ImageView
from RemoteViews
? All the remote views methods seems to take a Bitmap
.
推荐答案
RemoteViews
从XML资源描述都是建立。您不能使用code建造它们。
RemoteViews
are built from XML resource descriptors. You can not use code to build them.
您需要做的是这样的:
创建一个布局:
<ImageView android:src="@drawable/myshapedrawable">
</ImageView>
然后定义一个新的 myshapedrawable.xml
(在res /可绘制文件夹):
Then define a new shape drawable named myshapedrawable.xml
(in res/drawables folder):
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<size android:width="200" android:height="100"/>
<solid android:color="0xff74AC23"/>
</shape>
这篇关于从RemoteViews调用setImageDrawable的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!