简体   繁体   English

如何在TableLayout中将按钮相互粘贴?

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

在此处输入图片说明

1) How can I make all buttons stick to one another so that there is no space between any 2 buttons? 1)如何使所有按钮彼此粘在一起,以使任意两个按钮之间没有空间? 2) How can I make the picture of the bomb be inside the button as backround(I have it done wrongly) Here is some code how I added image: 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));

Thank you very much! 非常感谢你!

To make them stick together I would try removing any possible margins, since you already tried padding. 为了使它们粘在一起,我将尝试删除所有可能的边距,因为您已经尝试过填充。 If it doesn't work I would try to work some negative values that might do what I wanted. 如果它不起作用,我将尝试使用一些负值来实现我想要的功能。

As for the images in the buttons, I think you could use ImageButton instead of button. 至于按钮中的图像,我认为您可以使用ImageButton代替按钮。 Once it is clicked, it changes the background image (or not, I don't understand your game[?]). 单击后,它会更改背景图像(或不,我不理解您的游戏[?])。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM