开发者

Android RelativeLayout spacing

I'm just putting the finishing touches to my Android app. Unfortunately, I dug straight into development without reading the documentation and built my layout with AbsoluteLayout and it turned out to look terrible when I loaded the app on my phone. Now I'm redoing the UI in a RelativeLayout and I want to put empty canvas space in between my ViewGroups in the y-direction. I am currently achieving this by putting random TextView sentences that are of the same color as my View's background in order to make psuedo-empty space. Is there a better way to do this, because right now when I define a specific ViewGroup to be plac开发者_开发技巧ed below another View, it gets stuck right below the top View.

As I was writing this, it dawned upon me that using padding might be the answer.... Any other suggestions?


For each view in your xml layout, you can apply the android:layout_margin* where * is Top, Bottom, Left, or Right. You will also want to make sure to use dip units so it spaces the same on different displays.

One thought, you might want to be careful of using margins and padding to get it to look like you want, because phones like the droid with a taller screen than "standard" can really mess things up.

I suggest looking into placing frame style elements in their position using layout_alignParent* (Top, Bottom, etc.) and then, if, for example, you have a box of open space on the screen, align its corners with the framework elements which will be located correctly because of the parent alignment, and then use a sub LinearLayout that is centered (android:gravity="center_horizontal") for the interface buttons or whatever.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜