避免与Android重叠:layout_centerVertical =在RelativeLayout的
问题描述:
[编辑]避免与Android重叠:layout_centerVertical =在RelativeLayout的
“真” 鉴于:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="@+id/text1"
android:layout_width="match_parent"
android:layout_height="200dip"
android:background="#ff00ff00" />
<TextView
android:id="@+id/text2"
android:layout_width="match_parent"
android:layout_height="200dip"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:background="#ffff0000" />
</RelativeLayout>
我怎样才能避免在小屏幕上文本1和文本之间的重叠。重要提示:
如果可能的话,没有重叠,文本2,应准确地在屏幕的垂直中心显示
-
是否有重叠,文本2应该向下移动了一下,text1的
下面直接显示
答
将android:gravity="center_vertical"
添加到子代LinearLayout。这将使它成为父母的中心。
更改为button_container的android:layout_height="fill_parent"
。这将使其填充父级的剩余高度。您的代码会是这个样子的变化后:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ffff0000"
android:text="TextView" />
<LinearLayout
android:id="@+id/button_container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center_vertical"
android:orientation="vertical" >
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test" />
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="test" />
</LinearLayout>
谢谢,但这里的button_container是在剩余空间的中间,而不是在屏幕的中间。我需要它在屏幕中间(如果有足够的空间可用)。 – 2012-03-07 09:15:01
你已经改变了整个问题,所有尝试的答案现在已经脱离了语境。请把它作为一个单独的问题提出。 – Akhil 2012-03-07 12:36:41