我有如下的佈局Android的文字位置
<?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:background="@color/all_white"
android:gravity="center">
<Button android:id="@+id/mq_categories" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Browse Quiz Categories" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_random" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Enter Random Quiz" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_profile" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="My Profile" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
</LinearLayout>
這給輸出
現在我需要在添加一個歡迎文本屏幕的頂部部分
當我像這樣添加文本視圖時,只顯示歡迎文本並沒有任何按鍵和沒有滾動
<?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:background="@color/all_white"
android:gravity="center">
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mg_userinfo" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="Welcome"
android:gravity="center" />
<Button android:id="@+id/mq_categories" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Browse Quiz Categories" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_random" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Enter Random Quiz" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_profile" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="My Profile" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
</LinearLayout>
在下面試圖鋪陳歡迎文本在按鈕的下方顯示,但按鍵得到了轉移到了屏幕的頂部
<?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:background="@color/all_white"
android:gravity="center">
<Button android:id="@+id/mq_categories" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Browse Quiz Categories" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_random" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="Enter Random Quiz" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<Button android:id="@+id/mq_profile" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_margin="5dp"
android:text="My Profile" android:textColor="#EDFF99"
android:background="@drawable/custom_button" />
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mg_userinfo" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:text="Welcome"
android:gravity="center" />
</LinearLayout>
我該如何在頂部添加歡迎文字?屏幕上的中心按鈕?
不鼓勵使用px。它不能在不同屏幕密度的設備上正確縮放。始終使用dip或dp(兩者都相同)。 – Mudassir 2010-12-03 05:04:50