Hanzo
Hanzo

Reputation: 1899

Problems with "ImageView cell width" on tablelayout

I'm having troubles when tray to insert some images in a tablerow of tablelayout.

The first imageview expands the width of its own cell and the next images expands the rest of the row

How can i divide de row in five cells with equal size?

This is a snapshot of app

http://i41.tinypic.com/2dv77g6.png

This is the code of xml layout

<?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_marginRight="15dp"
        android:layout_marginTop="5dp"
        android:layout_weight="1"
        android:gravity="center_vertical|right"
        android:orientation="horizontal" >

        <ImageView
            android:id="@+id/user"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="5dp"
            android:contentDescription="@string/ES_user"
            android:gravity="right"
            android:src="@drawable/user" />

        <TextView
            android:id="@+id/TextUser"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="@string/ES_user"
            android:textColor="#ffffff"
            android:textSize="16sp"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/User"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text=""
            android:textColor="#ffffff"
            android:textSize="16sp" />

        <TextView
            android:id="@+id/TextLogout"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:gravity="right"
            android:text="@string/ES_logout"
            android:textColor="#fc0505"
            android:textSize="16sp"
            android:textStyle="bold" />
    </LinearLayout>

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

        <TableLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center|center_horizontal"
            android:background="@drawable/roundcorners"
            android:paddingBottom="20dp"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="20dp" >

            <TableRow android:layout_weight="1" >

                <ImageView
                    android:id="@+id/Logo"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center|center_horizontal"
                    android:layout_weight="0.5"
                    android:contentDescription="@string/ES_logo"
                    android:paddingRight="25dp"
                    android:src="@drawable/logotra" />

                <TableLayout
                    android:layout_width="wrap_content"
                    android:layout_gravity="center_horizontal"
                    android:layout_weight="0.5" >

                    <TableRow android:layout_weight="1" >

                        <TextView
                            android:id="@+id/Textpatient"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="left"
                            android:layout_weight="1"
                            android:text="@string/ES_codpatient"
                            android:textColor="#000000"
                            android:textSize="15sp" />
                    </TableRow>

                    <TableRow
                        android:layout_width="wrap_content"
                        android:layout_weight="1" >

                     <EditText
                            android:id="@+id/TxtCodPatient"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_weight="1"
                            android:inputType="text" />
                    </TableRow>

                    <TableRow
                        android:layout_width="match_parent"
                        android:layout_marginBottom="10dp"
                        android:layout_marginTop="5dp"
                        android:layout_weight="1" >

                        <ImageView
                            android:id="@+id/ESlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/esp" />

                        <ImageView
                            android:id="@+id/ENlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/en" />

                        <ImageView
                            android:id="@+id/CATlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/cat" />

                        <ImageView
                            android:id="@+id/GAlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/ga" />

                        <ImageView
                            android:id="@+id/EUlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/eusk" />

                        <ImageView
                            android:id="@+id/PTlanguagebtn"
                            android:layout_width="wrap_content"
                            android:layout_marginRight="10dp"
                            android:layout_weight="0.166"
                            android:src="@drawable/por" />
                    </TableRow>

                    <TableRow
                        android:layout_weight="1"
                        android:gravity="center" >

                        <Button
                            android:id="@+id/BtnStart"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_weight="0.5"
                            android:text="@string/ES_start" />
                    </TableRow>
                </TableLayout>
            </TableRow>
        </TableLayout>
    </LinearLayout>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginRight="10dp"
        android:layout_weight="1"
        android:gravity="center|right" >

        <TextView
            android:id="@+id/large_appname"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/ES_large_appname"
            android:textColor="#FFFFFF"
            android:textSize="20sp"
            android:textStyle="bold" />
    </LinearLayout>

</LinearLayout>

Upvotes: 0

Views: 1211

Answers (2)

GrIsHu
GrIsHu

Reputation: 23648

Try to set the layout of your 5 country images as below:

As you are giving your each ImageView weight then to get the best result you must have to give width of the ImageView as 0dp.

Replace your 5 country code with below code and check out.

         <TableRow
                    android:layout_width="fill_parent"
                    android:layout_marginBottom="10dp"
                    android:layout_marginTop="5dp"
                    android:layout_weight="1" >
                    <ImageView
                        android:id="@+id/ESlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:background="@drawable/icon" />
                    <ImageView
                        android:id="@+id/ENlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:src="@drawable/icon" />
                    <ImageView
                        android:id="@+id/CATlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:src="@drawable/icon" />
                    <ImageView
                        android:id="@+id/GAlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:src="@drawable/icon" />
                    <ImageView
                        android:id="@+id/EUlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:src="@drawable/icon" />
                    <ImageView
                        android:id="@+id/PTlanguagebtn"
                        android:layout_width="0dp"
                        android:layout_marginRight="10dp"
                        android:layout_weight="0.166"
                        android:src="@drawable/icon" />
                </TableRow>

Let me know if still any problem.

Thanks.

Upvotes: 2

RussVirtuoso
RussVirtuoso

Reputation: 888

Change this

  <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:layout_weight="1"
    android:gravity="center_vertical|right"
    android:orientation="horizontal" >

to this

  <LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginRight="15dp"
    android:layout_marginTop="5dp"
    android:layout_weight="1"
    android:gravity="center_vertical|right"
    android:orientation="horizontal" >

Upvotes: 0

Related Questions