简体   繁体   English

Android布局-将ImageButtons放置在屏幕的相等象限中,并按比例调整它们的大小

[英]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. 我正在创建一个android应用,而XML文件遇到了一些麻烦。 What I want is four ImageButtons displayed in the center of four quadrants of the layout (so one in each quadrant). 我想要的是在布局的四个象限的中心显示四个ImageButton(每个象限一个)。 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. 我还希望将theesImageButtons按屏幕的百分比设置(这样,在较大的屏幕上按钮会更大,在较小的屏幕上按钮会变小),但要达到特定大小的最大值。

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. 我在有效的布局中所拥有的功能的描述:包含thees按钮的布局占用了屏幕高度和最大宽度的70%(顶部还有30%的布局),并且屏幕被锁定为垂直方向。 so I'm only looking to complete this quadrant ImageButton style of view. 因此,我只希望完成这种象限的ImageButton样式的视图。

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. 1)网格布局:这将我的按钮包裹起来,它们没有占据整个屏幕,或者一个象限填充了整个屏幕,其他三个象限不可见。

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. 2)布局尺寸百分比:几个垂直和水平方向上的线性布局,并使用layout_hight = 0dp(或宽度),layout_weight =“ 0.50”“ trick”将象限定位。 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"). 这很好用,但是有一个警告,当您使用百分比在具有百分比位置的布局中调整布局的大小时,布局效率低下,并且ImageButtons不想停在最大尺寸,完全忽略了maxHight& maxWidth(我确实有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. 3)我可以通过计算大小并按代码放置所有内容来轻松完成所有这些工作,但是我真的很想在xml文件中执行此操作,并将其作为最后的选择。

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. 它简单得多,因为xml非常静态,而Java是动态的,在复杂情况下更易于使用。 Save yourself the trouble. 避免麻烦。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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