开发者

Android Text view position with custom buttons in the layout

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

Android Text view position with custom buttons in the layout

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="开发者_C百科@+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>

Android Text view position with custom buttons in the layout

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>

Android Text view position with custom buttons in the layout

How can I need to add a welcome text at the top section of the screen with button on the center?


Change the following property of textview:

android:layout_width="wrap_content"
android:layout_height="wrap_content" 

And put your textview above the buttons.


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"

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜