Android: comment créer un bouton sur Bitmap dynamiquement ou un bouton OVERLAYING?

J'essaie de créer des boutons BUTTON sur BITMAP ou OVERLAYING sur la vue. Je crée la signature numérique ici. Après la signature, j'ai besoin d'enregistrer pour cela, j'ai besoin d'un bouton. S'il vous plaît, quelqu'un m'aide. C'est très urgent. Je vous remercie

Voici mon code

import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.Bitmap.Config; import android.graphics.BitmapFactory; import android.graphics.BlurMaskFilter; import android.graphics.BlurMaskFilter.Blur; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.graphics.Path; import android.graphics.PorterDuff.Mode; import android.graphics.PorterDuffXfermode; import android.os.Bundle; import android.util.Log; import android.view.MenuItem; import android.view.MotionEvent; import android.view.View; import android.view.View.OnClickListener; import android.view.ViewGroup.LayoutParams; import android.widget.Button; import android.widget.TextView; public class FingerPaint extends GraphicsActivity implements OnClickListener { private TextView pauseButton; protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(new MyView(this)); Capture_SignatureActivity.writeLog("In FingerPaint class"); mPaint = new Paint(); mPaint.setAntiAlias(true); mPaint.setDither(true); mPaint.setColor(0xFF003F87); mPaint.setStyle(Paint.Style.STROKE); mPaint.setStrokeJoin(Paint.Join.ROUND); mPaint.setStrokeCap(Paint.Cap.ROUND); mPaint.setStrokeWidth(1); } private Paint mPaint; public void colorChanged(int color) { Capture_SignatureActivity.writeLog("In color changed"); mPaint.setColor(color); } public class MyView extends View{ private static final float MINP = 0.25f; private static final float MAXP = 0.75f; private Bitmap mBitmap; private Canvas mCanvas; private Path mPath; private Paint mBitmapPaint; private Bitmap overlayDefault; private Bitmap overlay; private Canvas c2; private Paint pTouch; private float X = -100; private float Y = -100; public MyView(Context c) { super(c); Capture_SignatureActivity.writeLog("In MyVIEW"); mPath = new Path(); mBitmapPaint = new Paint(Paint.DITHER_FLAG); mBitmap = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher); overlayDefault = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher); overlay = BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher).copy(Config.ARGB_8888, true); c2 = new Canvas(overlay); pTouch = new Paint(Paint.ANTI_ALIAS_FLAG); pTouch.setXfermode(new PorterDuffXfermode(Mode.SRC_OUT)); pTouch.setColor(Color.TRANSPARENT); pTouch.setMaskFilter(new BlurMaskFilter(15, Blur.NORMAL)); pTouch.setMaskFilter(startActivity(FingerPaint.this, Capture_SignatureActivity.class)); } @Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { super.onSizeChanged(w, h, oldw, oldh); System.out.println("w-->"+w+"-->"+"h--"+h+"-->"+"oldw-->"+oldh+"oldw-->"+oldw); Capture_SignatureActivity.writeLog("In onSizeChanged"); mBitmap = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888); mCanvas = new Canvas(mBitmap); } @Override protected void onDraw(Canvas canvas) { Capture_SignatureActivity.writeLog("In onDraw"); canvas.drawColor(0xFFFFFFFF); canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint); canvas.drawPath(mPath, mPaint); c2.drawBitmap(overlayDefault, 0, 0, null); //exclude this line to show all as you draw c2.drawCircle(X , Y , 80, pTouch); //draw the overlay over the background canvas.drawBitmap(overlay, 0, 0, null); } private float mX, mY; private static final float TOUCH_TOLERANCE = 4; private void touch_start(float x, float y) { Capture_SignatureActivity.writeLog("In touch_start"); mPath.reset(); mPath.moveTo(x, y); mX = x; mY = y; System.out.println("---- " +mX); } private void touch_move(float x, float y) { Capture_SignatureActivity.writeLog("In touch_Move"); float dx = Math.abs(x - mX); float dy = Math.abs(y - mY); if (dx >= TOUCH_TOLERANCE || dy >= TOUCH_TOLERANCE) { mPath.quadTo(mX, mY, (x + mX)/2, (y + mY)/2); mX = x; mY = y; } } private void touch_up() { Capture_SignatureActivity.writeLog("In touch_up"); mPath.lineTo(mX, mY); // commit the path to our offscreen mCanvas.drawPath(mPath, mPaint); // kill this so we don't double draw mPath.reset(); } @Override public boolean onTouchEvent(MotionEvent event) { Capture_SignatureActivity.writeLog("In touch_event"); float x = event.getX(); float y = event.getY(); switch (event.getAction()) { case MotionEvent.ACTION_DOWN: touch_start(x, y); invalidate(); break; case MotionEvent.ACTION_MOVE: touch_move(x, y); invalidate(); break; case MotionEvent.ACTION_UP: touch_up(); invalidate(); break; } return true; } public void onClick(View v) { //In myView startActivity(new Intent(FingerPaint.this, Capture_SignatureActivity.class)); } } public void onClick(View v) { //onCreate } @Override public boolean onCreateOptionsMenu(android.view.Menu menu) { super.onCreateOptionsMenu(menu); menu.add(0, 1, 0 , "Clear Screen"); menu.add(0, 2, 0 , "Exit Screen"); return true; } @Override public boolean onMenuItemSelected(int featureId, MenuItem item) { switch(item.getItemId()) { case 1: startActivity(new Intent(this, FingerPaint.class)); break; case 2: startActivity(new Intent(this, Capture_SignatureActivity.class)); break; } return super.onMenuItemSelected(featureId, item); } } 

Je suis en mesure de créer des images et des activités de démarrage. Permettez-moi de savoir comment résoudre ce problème.

2 Solutions collect form web for “Android: comment créer un bouton sur Bitmap dynamiquement ou un bouton OVERLAYING?”

Ici, j'ai eu la possibilité de créer des boutons dynamiques sur BITMAP & CANVAS

 public class MainAct extends GrapActivity implements OnClickListener { private Button saveButton; private Button clearButton; // onCreate Activity protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // content view signature = new MyView(this); // Dynamically created button on bitmap & canvas RelativeLayout myLayout = new RelativeLayout(this); myLayout.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // For Save Button saveButton = new Button(this); saveButton.setText("Save"); saveButton.setOnClickListener(this); // For Clear Button clearButton = new Button(this); clearButton.setText("Clear"); clearButton.setOnClickListener(this); myLayout.addView(signature); myLayout.addView(saveButton); myLayout.addView(clearButton); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT); //Alignments params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); params.addRule(RelativeLayout.ALIGN_PARENT_LEFT); saveButton.setLayoutParams(params); //Alignments RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(100, LayoutParams.WRAP_CONTENT); params2.addRule(RelativeLayout.ALIGN_PARENT_RIGHT); params2.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); clearButton.setLayoutParams(params2); saveButton.bringToFront(); clearButton.bringToFront(); this.setContentView(myLayout); new Thread(new RefreshRunner()).start(); // onclick listner for CLEAR button clearButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { //Activity for Clearing the Screen startActivity(new Intent(ThisAct.this, ThisAct.class)); finish(); } }); // onclick listner for SAVE button saveButton.setOnClickListener(new OnClickListener() { public void onClick(View v) { //capture the image try { saveAsJpg(mBitmap); startActivity(new Intent(ThisAct.this, MainActivity.class)); finish(); } catch (IOException e) { e.printStackTrace(); } } }); } } 

Merci les gars d'avoir aidé …

Si vous placez votre ImageView et votre Button intérieur d'un RelativeLayout ils se chevaucheront. Vous pouvez jouer avec le positionnement au besoin.

 <RelativeLayout android:layout_width="wrap_content" android:layout_height="match_parent" > <ImageView android:.... android:.... /> <Button android:.... android:.... /> </RelativeLayout> 
  • Dessinez un cercle dans une toile avec plusieurs couleurs dégradées
  • Canvas Android, plusieurs chemins avec différents montants de zoom
  • Android: Dessin sur toile, manière de faire en bas à gauche correspondent (0,0)?
  • Chartjs Donut disparaît
  • Dessiner un coeur avec Sharp Corner dans Android
  • Problème étrange sur la visionneuse Android avec toile
  • Comment dessiner du texte sur une toile?
  • Utilisation des ressources de mise en page dans un LiveWallpaper sur Android
  • coAndroid est un fan Android de Google, tout sur les téléphones Android, Android Wear, Android Dev et Android Games Apps.