剛剛開始Android開發,我在使用畫布簡單繪製視圖時遇到問題。安卓在畫布上繪製
據我瞭解,像這樣:
import android.content.Context;
import android.graphics.Canvas;
import android.view.View;
public class DrawView extends View
{
public DrawView(Context context)
{
super(context);
}
@Override
protected void onDraw(Canvas canvas)
{
super.onDraw(canvas);
canvas.drawRGB(255,0,0);
}
}
以此作爲我的活動:
public class Prototype1 extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
}
}
而本作的佈局:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<com.dhs2.prototype1.DrawView
android:id="@+id/map"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
應該只是隨處繪製紅色,但我只是得到一個空白屏幕。 任何想法我哪裏錯了?
你試過切換super.onDraw的順序()和canvas.drawRGB()? – scriptocalypse 2012-08-02 15:46:36