1

2 番目のステッカーをクリックすると、2 番目のステッカーだけが表示されます (最初のステッカーは削除されます)。ステッカー1(黄色)をクリックすると現在の出力が表示され、ステッカー1が画面に表示され、ステッカー2(赤)がクリックされると、前のステッカーがまだ画面に表示されます(これは望ましくありません)出力はステッカー2だけである必要がありますfor ループを実装しようとしましたが、うまくいきません。 完全なアクティビティ ソース コード 図 1 は現在の出力、図 2 と 3 はそれぞれ 1 回目と 2 回目のクリックの予想出力です。

public void addSticker(final Sticker sticker) {
  if (sticker == null) {
     Log.e(TAG, "Sticker to be added is null!");
     return;
   }

    float offsetX = (getWidth() - sticker.getWidth());
    float offsetY = (getHeight() - sticker.getHeight());
    sticker.getMatrix().postTranslate(offsetX, offsetY);
    float scaleFactor;
    if (getWidth() < getHeight()) {
         scaleFactor = (float) getWidth() / sticker.getDrawable().getIntrinsicWidth();
    } 
    else {
          scaleFactor = (float) getHeight() / sticker.getDrawable().getIntrinsicHeight();
      }
    sticker.getMatrix().postScale(scaleFactor, scaleFactor, getWidth(), getHeight());

    mHandlingSticker = sticker;
    mStickers.add(sticker);
    invalidate();
}
4

0 に答える 0