1

の上に表示される単純なコンパスビューを作成していMapViewます。およびその他のビューのレイアウトMapViewは、レイアウトxmlファイルで宣言されます。この記事を例として
使用しています。コンパスビューのメソッドを作成しましたが、何も表示されません。コンパスオブジェクトはメソッドで無効になります。画像が表示されないのはなぜですか?onDrawonSensorChanged

XMLレイアウト

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/main_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <com.mapviews.MyCompass
        android:id="@+id/compass"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="20dp" />

    <com.mapviews.TransparentPanel
        android:id="@+id/transparent_panel"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="3dp"
        android:padding="5dp" />

    <ImageButton
        android:id="@+id/map_zoom_out"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:contentDescription="@string/cd_zoom_out"
        android:src="@drawable/zoom_out" />

    <ImageButton
        android:id="@+id/map_zoom_in"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@id/map_zoom_out"
        android:contentDescription="@string/cd_zoom_in"
        android:src="@drawable/zoom_in" />

    <ImageButton
        android:id="@+id/map_center_user"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_toRightOf="@id/map_zoom_in"
        android:contentDescription="@string/cd_center_user"
        android:src="@drawable/directions" />

    <com.mapviews.MyMap
        android:id="@+id/mapView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:apiKey="MyAPIKey"
        android:clickable="true"
        android:state_enabled="true" />


MyCompassクラスの一部

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

        canvas.drawColor(Color.TRANSPARENT);

        canvas.rotate(
                -1 * Values.accelValues[0]
                , Values.width / 10
                , Values.height / 10);

        canvas.drawBitmap(
                bitmap
                , Values.width / 10 - bitmap.getWidth() / 10
                , Values.height / 10 - bitmap.getHeight() / 10
                , paint);
    }

    public void setup(Context c) {
        paint = new Paint();
        bitmap = BitmapFactory.decodeResource(c.getResources(), R.drawable.compass1);
    }


onCreate方法 で

    compass = (MyCompass) findViewById(R.id.compass);
    compass.setup(this);
    compass.bringToFront();
4

0 に答える 0