Hallo
Ich will bei meinem View ein rect auf eine position setzen,doch wenn die Position grösser ist als 100 wird’s nicht mehr angezeigt
Activity
package ding.din.di;
import android.app.*;
import android.os.*;
import android.view.*;
import android.widget.*;
import android.view.TouchDelegate;
import android.text.method.*;
import android.view.View.*;
import android.content.pm.*;
import android.graphics.Point;
public class MainActivity extends Activity
{
KBView v;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
v = new KBView(this, this);
setContentView(v);
}
View
package ding.din.di;
import android.view.View;
import android.graphics.*;
import android.util.AttributeSet;
import android.content.Context;
import android.app.*;
import android.widget.*;
import android.util.*;
public class KBView extends View
{
Canvas canvas;
Paint p;
Paint textp;
Bitmap bitmap;
boolean ding;
int rectx = 100;
int recty = 50;
int w;
int h;
public KBView(Activity c, MainActivity ma){
super(c);
DisplayMetrics dm = new DisplayMetrics();
ma.getWindowManager().getDefaultDisplay().getMetrics(dm);
w = dm.widthPixels;
h = dm.heightPixels;
this.onMeasure(w, h);
p = new Paint();
textp = new Paint();
textp.setTextSize(50);
bitmap = Bitmap.createBitmap(w, h, Bitmap.Config.RGB_565);
canvas = new Canvas(bitmap);
}
@Override
protected void onSizeChanged(int w, int h, int oldw, int oldh)
{
super.onSizeChanged(w, h, oldw, oldh);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
setMeasuredDimension(w, h);
}
@Override
protected void onDraw(Canvas c)
{
super.onDraw(c);
c.drawBitmap(bitmap, 0, 0, p);
repaint();
}
public void repaint(){
p.setColor(Color.GREEN);
canvas.drawRect(rectx,recty,100,100, p);
textp.setColor(Color.RED);
canvas.drawText("Hallo "+canvas.getWidth()+" "+canvas.getHeight()+" "+this.getWidth()+" "+getHeight(), 50, 50, textp);
invalidate();
}
}