簡體   English   中英

如何在TableLayout中將按鈕相互粘貼?

[英]How can I stick buttons to one another in TableLayout?

在此處輸入圖片說明

1)如何使所有按鈕彼此粘在一起,以使任意兩個按鈕之間沒有空間? 2)如何使炸彈的圖片在按鈕內作為背景(我做錯了)這是一些添加圖像的代碼:

clickedButton.setPadding(0,0,0,0);
        int newWidth = clickedButton.getWidth();
        int newHeight = clickedButton.getHeight();
        Bitmap originalBitmap = BitmapFactory.decodeResource(getResources(), R.drawable.b64);
        Bitmap scaledBitmap = Bitmap.createScaledBitmap(originalBitmap, newWidth, newHeight, true);
        Resources resource = getResources();
        clickedButton.setBackground(new BitmapDrawable(resource, scaledBitmap));

非常感謝你!

為了使它們粘在一起,我將嘗試刪除所有可能的邊距,因為您已經嘗試過填充。 如果它不起作用,我將嘗試使用一些負值來實現我想要的功能。

至於按鈕中的圖像,我認為您可以使用ImageButton代替按鈕。 單擊后,它會更改背景圖像(或不,我不理解您的游戲[?])。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM