fujihuynh
asked on
Layout help required for Android Eclipse
I am new to Android development and have been trying to implement a particular layout using Eclipse without any joy.
What I would like to implement are two toolbars at the top and bottom of the screen and a main panel in the middle.
The bottom toolbar has four buttons with images which should be spaced evenly although the text length of each button will vary.
I thought about implementing by using a table layout with three rows. In the third row, I have a LinearLayout and my four buttons.
Firstly is this the best way to get the layout that I want.
Secondly I can't seem to set the buttons to be of equal size and fill the screen i.e. each button takes up a quarter of the width.
What I would like to implement are two toolbars at the top and bottom of the screen and a main panel in the middle.
The bottom toolbar has four buttons with images which should be spaced evenly although the text length of each button will vary.
I thought about implementing by using a table layout with three rows. In the third row, I have a LinearLayout and my four buttons.
Firstly is this the best way to get the layout that I want.
Secondly I can't seem to set the buttons to be of equal size and fill the screen i.e. each button takes up a quarter of the width.
ASKER
Thanks but do you have an example of the XML layout resource rather than designing the layout programatically
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Can I ask whether there are advantages to creating the layout programmatically rather than using the XML files for layout as you say you never use xml layout.
Google advertises xml layout saying it is the best way to separate gui from code. I simply dont see any benefit in that approach since I then have to reference the objects defined in xml by id and type casting them to appropriate class.
I just dont think there is any real separation of layout code and business logic if you simply put the layout in xml - in the end you have to reference it and it is basicly the same as puting the layout code into a separate method. But that is just my opinion, you should use what you are most comfortable with.
Other than that I am not aware of any other advantages.
Here is the code that will show you how to achieve what you are after. Its all done through LinearLayout.
You have to play around with it a while and learn exactly how things work.
Open in new window