G
Gast2
Gast
Hi,
ich habe eine canvas erstellt und möchte diese nun auf meinem view anzeigen lassen.
Leider bekomme ich das nicht hin,
meine canvas wird nicht angezeigt.
Hier meine Quellen...
vielleicht kann mir jemand sagen (schreiben) was fehlt?!
activity_main.xml
[XML]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativ_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="26dp"
android:text="@string/hello_world"
android:textSize="30dp"
tools:context=".MainActivity" />
<ivi.uebungondraw2.DrawView
android:layout_below="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>[/XML]
MainActivity.java
DrawView.java
? ? ?
ich habe eine canvas erstellt und möchte diese nun auf meinem view anzeigen lassen.
Leider bekomme ich das nicht hin,
meine canvas wird nicht angezeigt.
Hier meine Quellen...
vielleicht kann mir jemand sagen (schreiben) was fehlt?!
activity_main.xml
[XML]<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/relativ_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="26dp"
android:text="@string/hello_world"
android:textSize="30dp"
tools:context=".MainActivity" />
<ivi.uebungondraw2.DrawView
android:layout_below="@+id/txv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
</RelativeLayout>[/XML]
MainActivity.java
Java:
package ivi.uebungondraw2;
import android.app.Activity;
import android.os.Bundle;
public class MainActivity extends Activity {
DrawView drawView;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
drawView = new DrawView(this);
}
}
DrawView.java
Java:
package ivi.uebungondraw2;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.view.View;
public class DrawView extends View {
Bitmap bitmap;
Canvas bitmapCanvas;
boolean isInitialized;
Paint paint = new Paint();
public DrawView(Context context) {
super(context);
paint.setColor(Color.BLACK);
paint.setStyle(Style.FILL_AND_STROKE);
isInitialized = false;
}
private void init() {
bitmap = Bitmap.createBitmap(470, 320, Bitmap.Config.RGB_565);
bitmapCanvas = new Canvas();
bitmapCanvas.setBitmap(bitmap);
bitmapCanvas.drawColor(Color.rgb(250, 250, 250));
isInitialized = true;
bitmapCanvas.drawLine(10, 10, 10, 300, paint);
bitmapCanvas.drawLine(10, 160, 310, 160, paint);
invalidate();
}
@Override
public void onDraw(Canvas canvas) {
if (!isInitialized)
init();
canvas.drawBitmap(bitmap, 0, 0, paint);
}
}
? ? ?