user859348
user859348

Reputation: 359

android - centre vertically and horizontally text with 2 buttons side-by-side beneath

I have a view. I want an image logo to appear in the top left of the layout and in the centre of the layout (both horizontally and vertically) I want text with 2 buttons (side-by-side) below the text. Here is what I have and it does not work...any help?

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/linearlayout"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:fillViewport="true"
  android:background="@drawable/login_background"
>

<ImageView 
       android:id="@+id/imgLogo"
       android:layout_width="wrap_content"
       android:layout_height="wrap_content"
       android:layout_x="-6px"
       android:layout_y="32px"
       android:background="@drawable/logo"
   />


  <RelativeLayout
    android:layout_width="fill_parent" android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    >
             <TextView android:id="@+id/txt1"
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:text="Welcome to my app. Please select your language"      
              android:textColor="#FFFFFF"
              android:textSize="20sp"
              />

              <LinearLayout
            android:orientation="horizontal"
            android:background="@android:drawable/bottom_bar"
            android:paddingLeft="4.0dip"
            android:paddingTop="5.0dip"
            android:paddingRight="4.0dip"
            android:paddingBottom="1.0dip"
            android:layout_width="fill_parent" android:layout_height="wrap_content"
            android:layout_below="@+id/TextView01"
            android:gravity="center"
            android:layout_centerInParent="true"
            >

                  <Button
                    android:id="@+id/btnEnglish"
                    android:layout_width="0.0dip" android:layout_height="fill_parent" 
                    android:text="English"
                    android:layout_weight="1.0"
                   /> 
                   <Button
                        android:id="@+id/btnSpanish"
                        android:layout_width="0.0dip" android:layout_height="fill_parent"
                        android:text="Spanish"
                        android:layout_weight="1.0"
                   /> 
            </LinearLayout>
</RelativeLayout>

Upvotes: 1

Views: 1475

Answers (1)

Steelight
Steelight

Reputation: 3357

I think this does what you want:

<ImageView
    android:id="@+id/imgLogo"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="-6px"
    android:layout_y="32px"
    android:background="@drawable/logo" />

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="0dp"
    android:layout_centerVertical="true"
    android:gravity="center_vertical"
    android:layout_weight="1"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/txt1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Welcome to my app. Please select your language"
        android:textColor="#FFFFFF"
        android:textSize="20sp" />

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/TextView01"
        android:layout_centerInParent="true"
        android:background="@android:drawable/bottom_bar"
        android:gravity="center"
        android:orientation="horizontal"
        android:paddingBottom="1.0dip"
        android:paddingLeft="4.0dip"
        android:paddingRight="4.0dip"
        android:paddingTop="5.0dip" >

        <Button
            android:id="@+id/btnEnglish"
            android:layout_width="0.0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:text="English" />

        <Button
            android:id="@+id/btnSpanish"
            android:layout_width="0.0dip"
            android:layout_height="fill_parent"
            android:layout_weight="1.0"
            android:text="Spanish" />
    </LinearLayout>
</LinearLayout>

Upvotes: 1

Related Questions