Hanzo
Hanzo

Reputation: 1899

Android Activity design

I'm Trying to add two buttons to register and log in in to a UI. The problem is that the images not center with the tablelayout, the first image gets all of the width of the row Someone cani help me?

this is the code

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient"
    android:gravity="center"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginLeft="10dp"
        android:layout_marginTop="10dp"
        android:layout_weight="1"
        android:gravity="right"
        android:orientation="horizontal" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="0dp"
            android:gravity="right" >

            <TableRow
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center_vertical"
                android:gravity="right" >

                <ImageView
                    android:id="@+id/ESlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/esp" />

                <ImageView
                    android:id="@+id/ENlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/en" />

                <ImageView
                    android:id="@+id/CATlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/cat" />

                <ImageView
                    android:id="@+id/GAlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/ga" />

                <ImageView
                    android:id="@+id/EUlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="10dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/eusk" />

                <ImageView
                    android:id="@+id/PTlanguagebtn"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="25dp"
                    android:contentDescription="@string/ES_info_pm1"
                    android:src="@drawable/por" />
            </TableRow>
        </TableLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:gravity="center" >

        <TableLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:background="@drawable/roundcorners"
            android:paddingBottom="20dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="20dp" >

            <TableRow>

                <TextView
                    android:id="@+id/Textheadwelcome"
                    android:layout_gravity="left"
                    android:text="@string/ES_bienvenida"
                    android:textColor="#000000"
                    android:textSize="30sp" />

            </TableRow>

            <TableRow>

                <TextView
                    android:id="@+id/Textheadwelcome2"
                    android:layout_width="match_parent"
                    android:layout_gravity="left"
                    android:text="@string/ES_bienvenida2"
                    android:textColor="#000000"
                    android:textSize="15sp" />
            </TableRow>

            <TableRow>

                <ImageView
                    android:id="@+id/logireg"
                    android:layout_width="wrap_content"
                    android:src="@drawable/registrarse1" />

                <ImageView
                    android:id="@+id/loginit"
                    android:layout_width="wrap_content"
                    android:src="@drawable/login1" />
            </TableRow>
        </TableLayout>
    </LinearLayout>

</LinearLayout>

And a screenshot of activity

enter image description here

Upvotes: 0

Views: 56

Answers (3)

Hariharan
Hariharan

Reputation: 24853

Try this..

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="10"
        android:gravity="center" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="40dp"
            android:layout_marginRight="40dp"
            android:background="#FFFFFF"
            android:orientation="vertical"
            android:paddingBottom="20dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="20dp" >

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/Textheadwelcome"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:text="@string/ES_bienvenida"
                    android:textColor="#000000"
                    android:textSize="30sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/Textheadwelcome2"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="left"
                    android:text="@string/ES_bienvenida2"
                    android:textColor="#000000"
                    android:textSize="15sp" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center" >

                <ImageView
                    android:id="@+id/logireg"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:src="@drawable/registrarse1" />

                <ImageView
                    android:id="@+id/loginit"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:src="@drawable/login1" />
            </LinearLayout>
        </LinearLayout>
    </LinearLayout>.

OR

         <TableRow>

            <ImageView
                android:id="@+id/logireg"
                android:layout_width="0dp"           //Use width as 0dp
                android:layout_gravity="center"      // and gravity as center
                android:layout_weight="1"            // Add weight as 1
                android:src="@drawable/registrarse1" />

            <ImageView
                android:id="@+id/loginit"
                android:layout_width="0dp"           //Use width as 0dp
                android:layout_gravity="center"      // and gravity as center
                android:layout_weight="1"            // Add weight as 1
                android:src="@drawable/login1" />
        </TableRow>

Upvotes: 2

vipul mittal
vipul mittal

Reputation: 17401

try:

<TableRow android:weightSum="2" >

    <ImageView
        android:id="@+id/logireg"
        android:layout_width="wrap_content"
        android:src="@drawable/registrarse1" android:layout_weight="1" android:layout_gravity="center"/>

    <ImageView
        android:id="@+id/loginit"
        android:layout_width="wrap_content"
        android:src="@drawable/login1" android:layout_weight="1" android:layout_gravity="center"/>
</TableRow>

Upvotes: 0

Joakim Engstrom
Joakim Engstrom

Reputation: 6403

Delete the android:layout_weight in the parent element on the linear layout, then add weight 1 to both the imageview.

That should line them right up.

Also consider doin Relative Layout instead those nested TableRows, could get a bit of a performance boost.

Upvotes: 0

Related Questions