Hi all,
I need your help!
I need to locate text on view as showed on the picture:
text 'Some more text' should be located in bottom|center_horizontal
text 'Short text' should be located on with align right, but about 10% from the top of the screen
text 'x.x.x.x' should be aligned to the center of the screen (right/bottom align of the 1st quater)
text 'Some long text ..' should be aligned to the top/left of the 3-rd quater of the screen, but it should cross the center_horizontal of the screen
eh ... something like this .. I hope, you're understand me :)
http://www.freeimagehosting.net/image.php?ca27bc012e.png
Please, help me!!!
Thanks for your help!
Answer:
Here a couple quick guidelines:
- Android Layouts tend to be much more deeply nested than you would normally expect. You often end up with "empty" layouts that just take up space so that other elements lay out correctly.
- RelativeLayout is your friend whenever you are aligning text to a particular edge.
- Use the padding settings to put text "a little away from" an edge.
- Gravity aligns the text within that TextView or button.
Looking again I your diagram, I reproduced it this way:
- Start with a relative layout ('fill_content') that takes up the entire screen.
- Put in the "short text" and "some more text" by anchoring to the top and bottom.
- Put a zero-width item with the property "centerInParent" for a point in the middle of the screen.
- Put the remaining to items above and aligned with that centerpoint.
Unfortunately, nothing in step 4 worked correctly. Nothing like "layout_below" worked when the referenced item was a centerInParent item. with relative layouts to step 3. Turns out it had to do with failing to fill_content on the top level. Yes, the layouts are tricky, and I wish there was a debugger for them.
Here's the correct version:
<?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/r1" android:layout_width="fill_parent" android:layout_height="fill_parent"> <TextView android:id="@+id/short_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Short Text" android:gravity="right" android:layout_marginTop="30dip" android:layout_alignParentTop="true" /> <TextView android:id="@+id/more_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Some More Text" android:gravity="center" android:layout_alignParentBottom="true" /> <TextView android:id="@+id/centerpoint" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="0dip" android:height="0dip" /> <TextView android:id="@+id/run_fox" android:text="Run, fox, run!" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_above="@id/centerpoint" android:layout_toLeftOf="@id/centerpoint" /> <TextView android:layout_below="@id/centerpoint" android:text="The quick brown fox jumped over the lazy dog, who had been a frog, and then got features and ran slowly." android:layout_alignRight="@id/centerpoint" android:layout_width="fill_parent" android:layout_height="wrap_content" /> </RelativeLayout>
<TextView android:id="@+id/centerpoint" android:layout_centerInParent="true" android:layout_width="wrap_content" android:layout_height="wrap_content" android:width="0dip" android:height="0dip" />
相关推荐
RelativeLayout android 布局练习
相对布局我最新喜欢的布局,也是game开发,照相机以及增钱现实中最常用的布局!
【Android开发学习25】界面布局之相对布局RelativeLayout(代码)
Android中使用RelativeLayout完成的梅花布局教学案例任务说明.pdf 学习资料 复习资料 教学资源
总结android中相对布局RelativeLayout的所有属性及使用方法。适合初级程序员
Android布局入门,LinearLayout和RelativeLayout的理解和应用
Android 相对布局 RelativeLayout 属性
一个Android XML布局的例子,主要利用xml文件进行布局,里边用到的是RelativeLayout。具体的本例中: 非洲草原地图:用到了FrameLayout的使用;ActivityMain演示了linerLayout。 个性化表单ActivityLayout 演示...
Android相对布局RelativeLayout的基本用法,相对布局是最实用的布局。
LinearLayout和RelativeLayout实现精确布局-简单版 类似与应用评价
android布局属性RelativeLayout详解.
Android中使用RelativeLayout布局完成的登录界面教学案例任务说明.pdf 学习资料 复习资料 教学资源
Android中使用RelativeLayout完成梅花布局的代码清单.pdf 学习资料 复习资料 教学资源
RelativeLayout是相对布局控件:以控件之间相对位置或相对父容器位置进行排列,下面通过本文给大家介绍Android布局之RelativeLayout相对布局,涉及到android relativelayout相对布局相关知识,对android ...
Android中使用RelativeLayout布局完成的登录练习题要求说明.pdf 学习资料 复习资料 教学资源
Android布局控件之RelativeLayout详解
下面我们举一个例子看看:例子里的机器人图片大小是250X250,可以看到我们使用android:layout_x和android:layout_y来指定子元素的纵横坐标。 <?xml version=”1.0″ encoding=”utf-8″?> <Absolute
在Android中画线必须由一个载体,要么是一个控件,要么是一个布局,其实他们都是继承自View,通过自定义控件或布局的方式画线是最常见的。这个例子实现了在自定义RelativeLayout中画网格线
前言 首先大家可以思考下如何用RelativeLayout而且没有嵌套生成下面的布局,如果你会的话就不用看后面的了。...如果是嵌套一个LinearLayout布局肯定就十分简单了,如果用RelativeLayout也是可以的,如下: <B
自定义RelativeLayout圆角图片背景,自定义属性 背景 圆角半径