0

ImageRenderer.java

public class ImageRenderer implements Renderer {
...

private Context mActivityContext;
...

public SandAniRenderer(final Context activityContext) {
    // TODO Auto-generated constructor stub
    mActivityContext = activityContext;
    mField = new Field(mActivityContext);
    ...
}

private boolean InitializeObject(int width, int height)
{
    ...
    Field.SetField(width, height, R.drawable.image);
    ...

    return true;
}

字段.java

public class Field extends xxx{

private final Context mActivityContext;

public Field(Context activityContext)
{
    mActivityContext = activityContext;
}

public boolean SetField(int width, int height, int fn)
{
    ImageView mImage = (ImageView) ((Activity) mActivityContext).findViewById(fn);
...
}

但它不起作用!

mImage 包含空图像...

我找不到图像如何包含在活动之外。

您能帮我了解如何在活动之外实现绘制 ImageView 吗?

4

2 回答 2

0

假设 mField 是一个成员变量,

public class ImageRenderer implements Renderer {
Field mField = null;

InitializeObject. 你Context是空的,因为当你静态调用它时它没有设置。

private boolean InitializeObject(int width, int height)
{
...
mField.SetField(width, height, R.drawable.image);
...

return true;
}

设置好之后

 mField = new Field(mActivityContext);
于 2013-02-25T01:17:10.607 回答
0

试试这个(emptyimage是我在我的drawable中的图像)

mImage.setImageResource(R.drawable.emptyimage);
于 2013-02-25T03:02:15.913 回答