質問

私は、しかし、私はエミュレータ画面に描かれ何も表示されません、ただ画面上にいくつかのテキストを描画するImageViewのを拡張してカスタムイメージビューを作成しますが、ログメッセージとprintlnsはログコンソールに印刷します。私が何かをやっていないだろうか?

これは私の活動である。

public class HelloAndroidActivity extends Activity
{
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);

        //        setContentView(R.layout.main);
        CustomImageView myView = new CustomImageView(getApplicationContext());
        System.out.println("Setting the view");
        myView.invalidate();
        setContentView(myView);
        System.out.println("Calling invalidate");
    }
}

これは私のCustomImageViewです。

public class CustomImageView extends ImageView
{

    /**
     * @param context
     */
    public CustomImageView(Context context)
    {
        super(context);
        // TODO Auto-generated constructor stub
        setBackgroundColor(0xFFFFFF);
    }

    /**
     * @param context
     * @param attrs
     */
    public CustomImageView(Context context, AttributeSet attrs)
    {
        super(context, attrs);
        // TODO Auto-generated constructor stub
    }

    /**
     * @param context
     * @param attrs
     * @param defStyle
     */
    public CustomImageView(Context context, AttributeSet attrs, int defStyle)
    {
        super(context, attrs, defStyle);
        // TODO Auto-generated constructor stub
    }

    @Override
    protected void onDraw(Canvas canvas)
    {
        // TODO Auto-generated method stub
                super.onDraw(canvas);
        System.out.println("Painting content");
        Paint paint  = new Paint(Paint.LINEAR_TEXT_FLAG);
        paint.setColor(0x0);
        paint.setTextSize(12.0F);
        System.out.println("Drawing text");
        canvas.drawText("Hello World in custom view", 100, 100, paint);
    }

    @Override
    public boolean onTouchEvent(MotionEvent event)
    {
        // TODO Auto-generated method stub
        Log.d("Hello Android", "Got a touch event: " + event.getAction());
        return super.onTouchEvent(event);

    }
}

onTouchEvent()でさえ、ログメッセージが印刷されますが、何も塗らないされます。

このレイアウトを持っている私のmain.xmlです。

<?xml version="1.0" encoding="utf-8"?>

<AbsoluteLayout android:layout_width="fill_parent" android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/AbsoluteLayout">
</AbsoluteLayout>
役に立ちましたか?

解決

のカラー値を使用しColor.WHITEするのまたはのColor.BLACK の代わりにヘキサ値の

他のヒント

は、あなたのキャンバスサイズを確認しましたか?画像表示は、ビットマップ/ドロウアブルがそのサイズを返し、scaletypeフラグに基づいて、ビューのサイズを決定することを期待します。私は、レイアウトのニーズに合わせてビューのサイズを決定し、あなたのコード内で何も表示されません。

-Rick

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top