Reputation: 51272
I've the following layout
<?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>
which gives the output as
Now I need to add a welcome text at the top section of the screen
When I added the text view like this, only welcome text is displayed and no buttons and no scroll
<?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>
When tried below lay out welcome text is displayed at the bottom of the buttons, but buttons got shifted to the top of the screen
<?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>
How can I need to add a welcome text at the top section of the screen with button on the center?
Upvotes: 0
Views: 5017
Reputation: 6353
Change the following property of textview:
android:layout_width="wrap_content"
android:layout_height="wrap_content"
And put your textview above the buttons.
Upvotes: 1
Reputation: 48
if you use
android:layout_height="fill_parent"
android will fill to full screen. you can use
android:layout_height="20DIP"
or
android:layout_height="20px"
Upvotes: 1