• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Table Layout - Size of a widget

 
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Rancher
Posts: 1369
1
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

 
Yes, of course, and I accept that blame. In fact, i covet that blame. As does this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic