Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Table Layout - Size of a widget

 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.)
 
Muhammad Imad Qureshi
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic