Bla*_*her 1 user-interface android android-sdk-1.6
我正在为我的第一个Android应用程序开发一个相当基本的屏幕布局并遇到一些问题.我的目标是在左上角和右上角有一个TextView,在屏幕的正中间有一个大的"hello world"TextView,然后是屏幕底部的一个按钮.我的问题是,要将"hello world"TextView垂直居中,我需要设置layout_height ="fill_parent".但是,这会导致中间TextView覆盖并隐藏屏幕底部的按钮.有没有比我正在尝试的更好的方法呢?我在下面附上了我的ui xml.谢谢!
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="center_horizontal">
    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="1">
        <TableRow>
            <TextView
                android:text="@string/label_left" />
            <TextView
                android:text="@string/label_right"
                android:gravity="right" />
        </TableRow>
    </TableLayout>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:text="@string/hello_world"
        android:gravity="center"
        android:textSize="40sp" />
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/next_activity"
        android:gravity="center"
        android:textSize="30sp" />      
</LinearLayout>
如果您使用RelativeLayout,则可以轻松地将其他视图对齐到屏幕的顶部/底部:
使用 android:layout_alignParentTop="true"
要么 android:layout_alignParentBottom="true"
左/右相同:
android:layout_alignParentLeft="true" or android:layout_alignParentRight="true"
那这个呢 ?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" 
android:layout_height="fill_parent" >
<TextView
    android:text="@string/label_left" 
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true" 
    android:layout_alignParentLeft="true"/>
<TextView
    android:text="@string/label_right"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:gravity="right" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentRight="true"/>
<TextView
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:text="@string/hello_world"
    android:gravity="center"
    android:textSize="40sp" 
    android:layout_centerInParent="true"/>
<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/next_activity"
    android:gravity="center"
    android:textSize="30sp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true"/>      
这是你在找什么?
| 归档时间: | 
 | 
| 查看次数: | 1034 次 | 
| 最近记录: |