简体   繁体   中英

android layout - position ImageButtons in equal quadrants of the screen and size them to proportion

I am creating an android app and I am having some trouble with the XML file. What I want is four ImageButtons displayed in the center of four quadrants of the layout (so one in each quadrant). I also want thees ImageButtons to be sized by a percent of the screen (so the button would be bigger on a bigger screen and smaller on a smaller screen) but to a maximum of a specific size.

description of what I have in the layout that works: The layout that contains thees buttons takes up 70% of the screen height and maximum width (there is another layout in the top 30%) and the screen is locked in vertical orientation. so I'm only looking to complete this quadrant ImageButton style of view.

my attempts to accomplish this was:

1) grid layout: this wrapped my buttons up and they did not take up the whole screen or one quadrant filled up the whole screen and the other three quadrants were not visible.

2) layout dimension percent: several linear layouts positioned in vertical and horizontal orientation and using the layout_hight=0dp (or width), layout_weight="0.50" "trick" to position the quadrants out. This worked nicely but there is a warning i get that the layouts are inefficient when you use a percentage to size a layout within a layout that was position with a percentage, and the ImageButtons did not want to stop at a maximum size completely ignored maxHight & maxWidth (i did have adjustViewBounds="true").

3) I can make all this work easily by calculating sizes and positioning everything by code but I would really like to do this in the xml file and leave that as a last resort.

I would appreciate any help, even a push in the right direction would be grate. I have been stuck on this for a while thank you.

Just do it programatically. It's much simpler as xml is very static and java is dynamic and in complex situations easier to use. Save yourself the trouble.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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