2017-04-14 29 views
0

私はXamarinを使用してAndroidアプリを構築しており、マップ上にいくつかのポイントを配置できる必要があります。このマップは、ImageViewを使用して表示された画像です(xmlから直接追加します)。 ビットマップとキャンバスを作ろうとしましたが、赤い点(必要に応じて)の黒い四角形が表示されますが、実際のマップは消えます。これは私のコードです:AndroidでImageView上にポイントを描画する(Xamarinを使用)

[Activity(Label = "Map")] 
public class Map : Activity 
{ 
    protected override void OnCreate(Bundle savedInstanceState) 
    { 
     base.OnCreate(savedInstanceState); 
     SetContentView(Resource.Layout.Map); 

     ImageView map = FindViewById<ImageView>(Resource.Id.imageView1); 
     Bitmap bitmap = Bitmap.CreateBitmap(500, 500, Bitmap.Config.Rgb565); 
     Paint paint = new Paint(); 
     paint.SetARGB(255, 255, 0, 0); 
     Canvas canvas = new Canvas(bitmap); 

     //Draw the image bitmap into the canvas 
     canvas.DrawBitmap(bitmap, 5, 5, paint); 

     //Draw everything you want into the canvas 
     canvas.DrawCircle(50, 50, 10, paint); 

     //Attach the canvas to the ImageView 
     map.SetImageDrawable((new BitmapDrawable(bitmap))); 

     Button item = FindViewById<Button>(Resource.Id.button1); //Declare item button 
     item.Click += delegate 
     { 
      StartActivity(typeof(Item)); 
     }; 
    } 
} 

問題は何ですか?

答えて

0

私はビットマップとキャンバスを作ってみましたが、赤い点(望み通り)の黒い四角形を表示しましたが、実際のマップは消えます。

map.SetImageDrawable((new BitmapDrawable(bitmap)));map.SetImageDrawable((new BitmapDrawable(bitmap)));あなたは作成したbitmapにマップを置き換えます。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/yourMapImage" 
    tools:context="com.example.winffee.scrollviewdemo.MainActivity"> 
    <ImageView 
     android:id="@+id/imgMap" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 

クイックフィックスとして、あなたはあなたのレイアウトの背景の代わりに、ImageViewのソースとして地図画像を設定することができます

関連する問題