hi i am trying to develop a code in which i try to add some buttons
and some textbox on canvas which contains bitmap image
but when i try to do so
i got code from google in which you can add linear layout with canvas
i modified it
and when i try to run it the linear layout which contain button
comes but the canvas coordinate starts where the layout ends
for example i added three buttons in vertical orientation and then try
to draw a circle the circle upper end is cut
the code is
package com.example;
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.LinearLayout;
public class abc extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
LinearLayout lmain = new LinearLayout(this);
lmain.setBackgroundResource(R.drawable.shortrangechart);
lmain.setOrientation(LinearLayout.VERTICAL);
Button b = new Button(this);
Button b1 = new Button(this);
Button b2 = new Button(this);
lmain.addView(b2, new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
lmain.addView(b, new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
lmain.addView(b1, new
LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
addCanvasBitmap(lmain, R.drawable.shortrangechart, true);
setContentView(lmain);
lmain.setFocusable(true);
}
private void addCanvasBitmap(LinearLayout lmain, int resource,
boolean scale) {
Bitmap bitmap;
bitmap = loadAndPrintDpi(resource, scale);
ScaledBitmapView view = new ScaledBitmapView(this, bitmap);
view.setLayoutParams(new
LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT));
lmain.addView(view);
}
private Bitmap loadAndPrintDpi(int id, boolean scale) {
Bitmap bitmap;
if (scale) {
bitmap = BitmapFactory.decodeResource(getResources(), id);
} else {
BitmapFactory.Options opts = new BitmapFactory.Options();
opts.inScaled = false;
bitmap = BitmapFactory.decodeResource(getResources(), id,
opts);
}
return bitmap;
}
}
class ScaledBitmapView extends View {
private Bitmap mBitmap;
public ScaledBitmapView(Context context, Bitmap bitmap) {
super(context);
mBitmap = bitmap;
}
@Override
protected void onMeasure(int widthMeasureSpec, int
heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
final DisplayMetrics metrics =
getResources().getDisplayMetrics();
setMeasuredDimension(
mBitmap.getScaledWidth(metrics),
mBitmap.getScaledHeight(metrics));
}
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
// canvas.drawBitmap(mBitmap, 0.0f, 0.0f, null);
Paint pOuterBullsEye = new Paint(Paint.ANTI_ALIAS_FLAG);
pOuterBullsEye.setStyle(Paint.Style.STROKE);
pOuterBullsEye.setColor(Color.GREEN);
canvas.drawCircle(150, 50,80,pOuterBullsEye );
}
}
please suggest what to do for this
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en