简体   繁体   English

图像顶部的Android布局

[英]Android Layout On Top of an Image

I am struggling with a Layout Problem on Android. 我在Android上遇到布局问题。 This is very simple to do on the iPhone, but with the various screen sizes and the Layout classes available. 这在iPhone上非常简单,但是具有各种屏幕尺寸和可用的Layout类。 I am having a hard time doing this. 我很难做到这一点。

One thing that I have noticed is that setting backgrounds on objects in the xml really messes up the layout on the device. 我注意到的一件事是,在xml中的对象上设置背景确实弄乱了设备上的布局。 I generally have to put in a FrameLayout and an ImageView to get a background. 我通常必须放入FrameLayout和ImageView以获得背景。

So Am trying to get to this. 所以我试图做到这一点。 http://www.calidadsystems.com/images/AndroidListItem.png (Sorry I don't have enough pts to post the image) http://www.calidadsystems.com/images/AndroidListItem.png (对不起,我没有足够的分数来发布图像)

his is a status view and is an item in a List View. 他是状态视图,是列表视图中的一项。 There are 8 TextViews that need to be set. 有8个TextViews需要设置。 Each of the 222 fields will change. 222个字段中的每个字段都会更改。 The current background has the colors in there at specific locations and I am trying to line up the Labels and TextViews to get the picture below. 当前的背景在特定位置有颜色,我正在尝试将Labels和TextViews对齐以获得下面的图片。 I built this one with AbsoluteLayout which is deprecated, but it also does not work very well on the device. 我使用AbsoluteLayout构建了此版本,但该版本已过时,但在设备上也无法很好地工作。

I have constantly struggled with the layouts on Android. 我一直在与Android上的布局作斗争。 Does someone have some good sample code that could do this? 有人有一些好的示例代码可以做到这一点吗?

You're probably going to want to use a RelativeLayout. 您可能要使用RelativeLayout。 You can use the android:layout_alignTop="id" attribute to make the rows be in line correctly. 您可以使用android:layout_alignTop =“ id”属性使行正确对齐。 And android:layout_alignLeft="id" for the columns. 和android:layout_alignLeft =“ id”为列。 Other than that its just a matter of playing with the android:layout_marginLeft="XXdip" attribute to get the space between them how you want it. 除此之外,仅需使用android:layout_marginLeft =“ XXdip”属性即可在它们之间获得所需的空间。 Check out this page for an overview and examples of all of the Layout types. 请查看此页面以获取所有布局类型的概述和示例。 Here is some more sample RelativeLayout code. 这是更多示例RelativeLayout代码。 And one more page with another example. 还有一个页面和另一个示例。 RelativeLayout is a bit tricky to get used to but once you've used it a few times its pretty easy to understand and get the Layout that you want. RelativeLayout习惯起来有些棘手,但是一旦使用了几次,它就很容易理解并获得所需的Layout。 The benefit of it is that your UIs look nice on several different screen sizes when you define them this way. 这样做的好处是,以这种方式定义UI时,它们在几种不同的屏幕尺寸上看起来都很好。

Why not just composed the layout in a table layout and set the table layout's background to a custom made graphic you make? 为什么不只是在表格布局中组成布局并将表格布局的背景设置为您制作的定制图形呢? This should work well with you. 这应该适合您。 Specifically the design of your design would be like 4 columns with x rows. 具体来说,您设计的设计将像是4列x行。 Then using the strechcolumn property, you should be able to accomplish what you are trying to do! 然后使用strechcolumn属性,您应该能够完成您想做的事情!

If you scale the graphic properly, then you shouldn't have this problem overall. 如果正确缩放图形,那么总体上就不会出现此问题。

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

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