0
지도로 안드로이드 게임을 만들려고합니다 (지금은 서클을 그려 보려고합니다). 그리고 우리가 만든 화면이 제대로 팽창하지 않을 것이고, 앱이 계속 충돌합니다.맞춤보기가 적절하게 팽창하지 않음
활동
package edu.virignia.cs2110.dlf4mf.ghostapocalypse;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
public class GameActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_game);
MapView mv = (MapView)findViewById(R.id.map_view);
}
}
활동 레이아웃
<RelativeLayout 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"
tools:context="${relativePackage}.${activityClass}" >
<MapView
android:id="@+id/map_view"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</RelativeLayout>
사용자 정의보기
package edu.virignia.cs2110.dlf4mf.ghostapocalypse;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Point;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.view.Display;
import android.view.SurfaceView;
import android.view.View;
public class MapView extends SurfaceView {
private final Paint mPaint = new Paint();
public MapView(Context context) {
super(context);
init();
}
public MapView(Context context, AttributeSet attrs) {
super(context, attrs);
init();
}
public MapView(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init(){
int h = 500;
int w = 500;
Canvas grid = new Canvas(Bitmap.createBitmap(h,w, Bitmap.Config.ARGB_8888));
draw(grid);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
mPaint.setStyle(Paint.Style.FILL);
int c = R.color.material_deep_teal_500;
mPaint.setColor(c);
canvas.drawCircle(250, 250, 150, mPaint);
}
}