Reputation: 141
I want to have a background in my activity which represents the building. I want to draw a small dot/circle which represents actual position of the phone, but I can't figure out, how should be done. I read some topics, write this:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
SurfaceView surface = (SurfaceView) findViewById(R.id.surface);
surface.getHolder().addCallback(new SurfaceHolder.Callback() {
@Override
public void surfaceCreated(SurfaceHolder holder) {
// Do some drawing when surface is ready
Canvas canvas = holder.lockCanvas();
Paint paint = new Paint();
paint.setColor(Color.RED);
canvas.drawRect(50, 50, 200, 200, paint);
//canvas.drawColor(Color.RED);
holder.unlockCanvasAndPost(canvas);
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
}
});
}
}
and this:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@mipmap/map"
>
<SurfaceView
android:id="@+id/surface"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</FrameLayout>
But it doesn't work, when it runs, the map disappear, and only the red rectangle is visible.
My question is: what should be done to leave the background map?
Upvotes: 0
Views: 1015
Reputation: 1499
You will have to make the SurfaceView transparent in order to do that. Check out this answer here : https://stackoverflow.com/a/7061396/5512274
All the best :)
Upvotes: 1