user710502
user710502

Reputation: 11469

Change Background

I am new to android and I have an image in my drawable folder which I was able to load as my background, now I would like to draw on top of the background but havent been able to, how can achieve this... I have the following, all i want is to draw a circle on top of the image background

    <?xml version="1.0" encoding="utf-8"?>
<FrameLayout android:id="@+id/my_view"
    xmlns:android="http://schemas.android.com/apk/res/android"    
    android:layout_width="fill_parent"    
    android:layout_height="fill_parent"    
    android:background="@drawable/background">        
</FrameLayout> 

        //MY ACTIVITY
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);
             setContentView(R.layout.main);
         }
       //IN MY VIEW CLASS
            public GameView(Context context, float x, float y, int r) {
        super(context);
        setFocusable(true);
        mPaint.setColor(Color.YELLOW);
        this.x = x;
        this.y = y;
        this.r = r;
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);
         canvas.drawCircle(x, y, r, mPaint);
    } 

Upvotes: 0

Views: 422

Answers (2)

krupa parekh
krupa parekh

Reputation: 500

To set the image as background use ImageView in Absolute Layout.Enter code to set img as background :


android:background="@drawable/icon1"

Now you would be able to have circle over the image view

Upvotes: 1

Sumant
Sumant

Reputation: 2805

use ImageView in xml file & set what u want to draw on background.

Upvotes: 1

Related Questions