Android 应用程序布局 - LinearLayout、TableLayout 和relativeLayout 呃?
我一直在寻找设计 Android UI 的最佳实践。虽然有很多关于实际代码编程的信息,但有关 Android 高级 xml 设计的教程却很少。如果您知道任何教程,请在此处链接。
我目前发现自己使用 TableLayout 来实现一些更复杂的 UI 布局,效果不错。我喜欢我不需要为 TableLayout 提供任何固定的宽度或高度值,但是,我不得不使用奇怪的解决方法,例如两个按钮之间的空白来创建假的第三列,诸如此类的东西。
我知道肯定有一种比使用表格和假的RelativeLayouts作为间隔更好的方法,有人可以解释一下RelativeLayouts如何在不同的设备上工作吗?例如,如果您有 LDPI 设备,由于宽度和高度像素较少,它会以不同的方式显示您的 UI吗?如果您使用 480px(hdpi 标准宽度)作为宽度属性并且您的 UI 显示在 LDPI 设备上怎么办?会溢出屏幕吗?
我的桌子和垫片技巧效果非常好,几乎足以坚持使用它,但是,我想正确设计我的 UI,以便它适用于尽可能多的设备!请为我指明正确的方向,干杯!
I've been looking on best practices for designing Android UI's. While there is a lot of information out there around programming the actual code, there are very few tutorials on doing advanced xml design for Android. If you know of any tutorials, please link them here.
I currently find myself using TableLayout with decent results to achieve some more complex UI layouts. I like that I don't need to supply TableLayout with any fixed width or height values, however, I have had to use strange work-arounds like an empty between two buttons to create a fake 3rd column, stuff like that.
I know there must be a better way than using tables and fake RelativeLayouts for spacers, can someone please explain how RelativeLayouts work on different devices. For instance, if you have a LDPI device, will it display your UI differently as it has less width and height pixels? What if you used 480px (hdpi standard width) as a width property and your UI was displayed on a LDPI device? Would it overflow the screen?
My tables and spacers trick works pretty good, it's almost good enough to stick with it, however, I want to design my UI properly so it works with the most devices possible! Please point me in the right direction, cheers!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
相对布局是一个很好的方法。如果您使用 dp 设置视图的距离和大小,则这些以 dp 为单位的距离将被视为 MDPI 屏幕上的像素,并且它们将被缩放,以便您的布局在 LDPI 和 HDPI 屏幕上均匀地填充空间。 Android 开发人员关于视图的教程有一个关于相对布局的很好的部分。
RelativeLayout is a great way to go. If you set Views' distances and sizes with dp, those distances in dp will be treated as pixels on an MDPI screen, and they will be scaled so your layouts fill the space equally on LDPI and HDPI screens. The Android Developers tutorial on views has a good section on RelativeLayouts.