geschichtete Bilder plus Leinwand
-
24-10-2019 - |
Frage
Ich versuche, zwei Bild übereinander zu legen. Top ist transparent. Darüber hinaus versuche ich, eine transparente Leinwand hinzuzufügen, damit der Benutzer zeichnen, tippen kann, was auch immer er tun muss, und die beiden unteren Bilder sind sichtbar.
So kann ich die beiden Bilder zum Anzeigen bringen oder nur die Leinwand. Jedes Mal, wenn ich versuche, die Leinwand anzuzeigen, scheint es, als ob sie [P der beiden Bilder, die sie abdecken.
Hier ist was ich bisher habe ..
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(new MyView(this));
..... some code to set up the paint
}
private Paint mPaint;
private MaskFilter mEmboss;
private MaskFilter mBlur;
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;
public MyView(Context c) {
super(c);
// Creating a new relative layout add the definition again.
RelativeLayout relativeLayout = new RelativeLayout(TwoPicksOnEachOther.this);
// Setting the orientation to vertical
////relativeLayout.setOrientation(LinearLayout.VERTICAL);
// Creating Fish image
final ImageView iv = new ImageView(TwoPicksOnEachOther.this);
iv.setImageResource(R.drawable.fish2);
// relative layout parameters
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
//iv.setId(1);
relativeLayout.addView(iv,lp);
// Creating transparent image with boat.
final ImageView iv2 = new ImageView(TwoPicksOnEachOther.this);
iv2.setImageResource(R.drawable.ctdeasytwo);
//iv2.setId(2);
RelativeLayout.LayoutParams lp2 = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
relativeLayout.addView(iv2,lp2);
mBitmap = Bitmap.createBitmap(480, 800, Bitmap.Config.ARGB_8888);
//mBitmap = BitmapFactory.decodeResource(getResources(),
// R.drawable.ctdeasytwo);
mCanvas = new Canvas(mBitmap);
// mCanvas.drawBitmap(mBitmap, 10, 10, null);
mPath = new Path();
mBitmapPaint = new Paint(Paint.DITHER_FLAG);
}
@Override
protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
................... More code to manage touch events.
Jetzt vermute ich, dass die Leinwand nicht Teil des relativen Layouts ist. Könnte das das Problem sein? Wenn ja, kann ich nicht relATelayout.addView (McANvas, LP) machen;
Irgendwelche Vorschläge?
Lösung
Entschuldigung musste acht Stunden warten, um meine eigene Frage zu beantworten.
Ich konnte das Problem beheben. Ich habe eine Klasse erstellt.
public class newClass extends View {
public newClass (Context context){ super(context); }
...
@Override protected void onDraw(Canvas canvas) {
canvas.drawColor(Color.TRANSPARENT); }
Dann musste ich nur noch tun
final newClass myCanvas = new newClass (this);
relativeLayout.addView(myCanvas,lp2);
Funktioniert gut...
Andere Tipps
Ich habe es geschafft, etwas Ähnliches zu tun (Farbe auf einer transparenten Leinwand mit einem Hintergrundbitmap dahinter), indem ich folgende (nur Teile des Codes werden angezeigt werden):
public class MyView extends View {
public MyView(Context c) {
super(c);
Bitmap tmpBitmap;
// Create the background bitmap and convert it to a drawable object
mBackBitmap = Bitmap.createBitmap(tmpBitmap, 0, 0, tmpBitmap.getWidth(), tmpBitmap.getHeight(), aMatrix, false);
mBackBitmapDrawable = new BitmapDrawable(mBackBitmap);
// Set the drawable object as the background
setBackgroundDrawable(mBackBitmapDrawable);
// Create an empty bitmap for the canvas
mBitmap = Bitmap.createBitmap(tmpBitmap.getWidth(), tmpBitmap.getHeight(), Bitmap.Config.ARGB_8888);
mCanvas = new Canvas(mBitmap);
}
@Override
protected void onDraw(Canvas canvas) {
//Log.d("MyView", "onDraw");
// Use transparent background
canvas.drawColor(Color.TRANSPARENT);
canvas.drawBitmap(mBitmap, 0, 0, mBitmapPaint);
canvas.drawPath(mPath, mPaint);
}
}
Ich hoffe es hilft.
Du kannst das verweisenBild in Leinwand mit Berührungsereignissen