我正在嘗試開發一個簡單的地圖應用程序,它將在屏幕上顯示地圖。如何在Android上通過ImageView繪製線條?
當用戶在屏幕上移動光標時,我想在我的地圖上顯示2條垂直線。我曾嘗試過很多例子來獲得這個想法,但不幸的是,它並沒有成功。 我該如何做到這一點?
作爲前一個問題here我曾試過。但沒有得到答案。任何人都可以引導我?
我的main.xml是如下:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:id="@+id/main_imagemap"
android:src="@drawable/worldmap"
android:clickable="true"
android:layout_width="fill_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
而且我的活動文件(我剛剛開始吧..)
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
public class LineMapActivity extends Activity
{
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ImageView map_image = (ImageView)findViewById(R.id.main_imagemap);
}
}
而且在該鏈接時,我也有加入MyImageView 。
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.widget.ImageView;
public class MyImageView extends ImageView
{
public MyImageView(Context context) {
super(context);
// TODO Auto-generated constructor stub
}
@Override
protected void onDraw(Canvas canvas) {
// TODO Auto-generated method stub
Paint p = new Paint(Paint.ANTI_ALIAS_FLAG);
canvas.drawLine(0, 0, 20, 20, p);
super.onDraw(canvas);
}
}
現在我該如何將MyImageView添加到我的應用程序?
更多的細節?看看這個教程http://codemagician.wordpress.com/2010/05/06/android-google-mapview-tutorial-done-right/ – MikeIsrael 2012-01-12 07:50:21
沒有我親愛的..我只是一個新的蜜蜂在andriod ..我是隻需添加drawable的圖像即可。我只是想研究如何在圖像上方畫線。就像在舊的黑莓手機 – 2012-01-12 07:58:35
好吧,檢查我的答案,它應該得到你想要的結果。 – MikeIsrael 2012-01-12 08:21:06