开发者

2 different views in android setContentView

I need to have 2 different images in one view. The GraphicsView(this) is supposed to be an animation (actually an image that rotates it self in the center of the view) and R.layout.main is supposed to be the background of the view (a static image again on the top of the view)

What I need is an imageview on the top of the view and bellow the animation view I have

    public class spinball extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        setContentView(new GraphicsView(this));
        setContentView(R.layout.main);
}
    private static class GraphicsView extends View {
        private Bitmap ball;
            private int XOffset;
            private int YOffset;

        private Animation anim;

        public GraphicsView(Context context) {
            super(context);
            ball = BitmapFactory
                    .decodeResource(getResources(), R.drawable.ball);
            XOffset = ball.getWidth() / 2;
            YOffset = ball.getHeight() / 2;
        }
        private void createAnim(Canvas canvas) {
            anim = new RotateAnimation(0, 360, canvas.getWidth() / 2, canvas
                    .getHeight() / 2);
            anim.setRepeatMode(Animation.RESTART);
            anim.setRepeatCount(Animation.INFINITE);
            anim.setDuration(10000L);
            anim.setInterpolator(new AccelerateDecelerateInterpolator());

            startAnimation(anim);
        }
        @Override
        protected void onDraw(Canvas canvas) {
            super.onDraw(canvas);

            // creates the animation the first time
            if (anim == null) {
                createAnim(canvas);
            }

            Path circle = new Path();

          开发者_如何学C  int centerX = canvas.getWidth() / 2;
            int centerY = canvas.getHeight() / 2;
            int r = Math.min(centerX, centerY);

            circle.addCircle(centerX, centerY, r, Direction.CW);
            Paint paint = new Paint();
            canvas.drawBitmap(ball, centerX - jobsXOffset,
                    centerY - jobsYOffset, null);
        }
    }
}

main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    >
    <ImageView android:src="@drawable/static_image"
       android:layout_width="fill_parent"
       android:layout_height="wrap_content"
       android:background="#FFFFFF"
       />
</LinearLayout>


Use RelativeLayout. Later children of the RelativeLayout stack "on top of" (Z-axis) earlier children.


An activity can only have one content view. If you want to just have a background image you can set the background drawable of your top level layout, and have that layout contain the ImageView. Is that what you are going for?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜