Meaningless Drivel is fun!*
The moose likes Android and the fly likes Table Layout - Size of a widget Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Mobile » Android
Bookmark "Table Layout - Size of a widget" Watch "Table Layout - Size of a widget" New topic
Author

Table Layout - Size of a widget

Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
I have following code



I want all buttons to be same size. But the button in the middle of each row is larger than the two (to fill up space). How can I adjust their sizes. I am sure it can be done without using "dip" or any other manual method. Thanks.
Imad
Monu Tripathi
Rancher

Joined: Oct 12, 2008
Posts: 1369
    
    1

the button in the middle of each row is larger than the two (to fill up space).

I suspect this is because you have the following attribute set in your TableLayout:
android:stretchColumns="1"

If you set width of a button to "wrap_content" the button is sized large enough to hold the contents(the button text). So, depending on what text you set for a button each Button size will vary unless you hardcode a fixed value for the width.
Also, layout_weight will just specify the ratio in which the extra space is to be split across views. So, if the buttons are not of same width splitting the extra space evenly would not make all the buttons of same size.

An option you can consider is having all the button texts of same length(by using padding etc.)


[List of FAQs] | [Android FAQ] | [Samuh Varta]
Muhammad Imad Qureshi
Ranch Hand

Joined: Sep 13, 2005
Posts: 238
Thanks for your help Monu. I resolved the problem. Here is what I did. Per your recommendation I removed the stretch column attribute. That resolved the problem of size difference. All buttons were same size but there was extra space left on each row. For that I added 'android:layout_weight="1"' and that made all buttons equal size and fill up the remaining space on screen. Here is my final code in case it might help someone in future.

Thanks
Imad

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Table Layout - Size of a widget