开发者

Background image with moving foreground graphics

I would like to know what the best way would be to draw a background image (this would b开发者_如何学JAVAe pretty much static) and a foreground object which would move depending on user input in Android?

Sort of like a side-scroller game (when the foregroudn object needs to animate and change a lot more than the background).

TIA


You could set the background image as main view with setContentView. For drawing foreground image You could use custom class that extends View and do drawing in it "onDraw" method. Something like this:

class ForegroundImage extends View
{
    public Foreground(Context ctx) {}

    public void onDraw(Canvas c)
    {
        //here You draw image anything You want on canvas
    }
}

ImageView lBackgroundImage = (ImageView)findViewById(R.id.BackgroundView);
setContentView(lBackgrounImage);
ForegroundImage lForegroundImage = new ForegroundImage(this);
addContentView (lForegroundImage);

I hope this helped

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜