Johnny H.
Johnny H.

Reputation: 1

Android Linear Layout issue

I have a problem with dividing the LinearLayout(Horizontal) into three columns (vertical columns).

Can someone look into the XML and advise ?

XML below:

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="100" >

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="40"
                    android:orientation="vertical" >

                    <ImageButton
                        android:id="@+id/ibTakeCheckPhoto"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_gravity="left"
                        android:layout_weight="1"
                        android:src="@drawable/camera" />
                </LinearLayout>

                <View
                    android:layout_width="2dp"
                    android:layout_height="fill_parent"
                    android:background="@android:color/darker_gray" />

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="30"
                    android:orientation="vertical" >

                    <TextView
                        android:id="@+id/checkLayoutIDTV"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Check Number"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/checkLayout_amountTV"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:text="Amount"
                        android:textStyle="bold" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"
                    android:layout_weight="30"
                    android:orientation="vertical" >

                    <EditText
                        android:id="@+id/checkLayoutIDET"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:hint="Check No."
                        android:inputType="number" >
                    </EditText>

                    <EditText
                        android:id="@+id/checkLayout_amounET"
                        android:layout_width="0dp"
                        android:layout_height="wrap_content"
                        android:layout_weight="1"
                        android:ems="5"
                        android:hint="Amount"
                        android:inputType="number" />
                </LinearLayout>

Upvotes: 0

Views: 340

Answers (3)

Meghna
Meghna

Reputation: 537

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"

                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal"
                android:weightSum="100" >

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_weight="24.33"
        android:orientation="vertical" >

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

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/checkLayoutIDTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Check Number"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textStyle="bold" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <TextView
                    android:id="@+id/checkLayout_amountTV"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:text="Amount"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:textStyle="bold" />

            </TableRow>

        </TableLayout>

    </LinearLayout>

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

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

            <TableRow
                android:id="@+id/tableRow6"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" >

                <EditText
                    android:id="@+id/EditText01"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:ems="5"
                    android:hint="Amount"
                    android:inputType="number" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <EditText
                    android:id="@+id/checkLayoutIDET"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:hint="edit2"
                    android:inputType="number" />

            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" >

                <EditText
                    android:id="@+id/checkLayout_amounET"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_weight="1"
                    android:ems="5"
                    android:hint="Amount"
                    android:inputType="number" >

                    <requestFocus />
                </EditText>

            </TableRow>

        </TableLayout>

    </LinearLayout>

                                </LinearLayout>

may b it fulfill your requirement..

Upvotes: 1

Avinash Kumar Pankaj
Avinash Kumar Pankaj

Reputation: 1720

i think this is what you wanted

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:orientation="horizontal"
  android:weightSum="10" >

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="4"
    android:orientation="vertical" >

    <ImageButton
        android:id="@+id/ibTakeCheckPhoto"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_gravity="left"
        android:layout_weight="1"
        android:src="@drawable/ic_launcher" />
</LinearLayout>

<View
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:background="@android:color/darker_gray" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/checkLayoutIDTV"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Check Number"
        android:textStyle="bold" />

    <TextView
        android:id="@+id/checkLayout_amountTV"
        android:layout_width="60dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Amount"
        android:textStyle="bold" />
</LinearLayout>

<View
    android:layout_width="2dp"
    android:layout_height="fill_parent"
    android:background="@android:color/darker_gray" />

<LinearLayout
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="3"
    android:orientation="vertical" >

    <EditText
        android:id="@+id/checkLayoutIDET"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:hint="Check No."
        android:inputType="number" >
    </EditText>

    <EditText
        android:id="@+id/checkLayout_amounET"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:ems="5"
        android:hint="Amount"
        android:inputType="number" />
</LinearLayout>

Upvotes: 0

vasart
vasart

Reputation: 6702

Use android:layout_width="fill_parent" instead of android:layout_width="0dp" in ImageButton, TextView and EditText.

Resulting layout will look like this

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="100" >

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="40"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/ibTakeCheckPhoto"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_gravity="left"
            android:src="@drawable/camera" />
    </LinearLayout>

    <View
        android:layout_width="2dp"
        android:layout_height="fill_parent"
        android:background="@android:color/darker_gray" />

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="fill_parent"
        android:layout_weight="30"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/checkLayoutIDTV"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="Check Number"
            android:textStyle="bold" />

        <TextView
            android:id="@+id/checkLayout_amountTV"
            android:layout_width="fill_parent"
            android:layout_height="0dp"
            android:layout_weight="1"
            android:text="Amount"
            android:textStyle="bold" />
    </LinearLayout>

    <LinearLayout
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="30"
        android:orientation="vertical" >

        <EditText
            android:id="@+id/checkLayoutIDET"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:hint="Check No."
            android:inputType="number" >
        </EditText>

        <EditText
            android:id="@+id/checkLayout_amounET"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:ems="5"
            android:hint="Amount"
            android:inputType="number" />
    </LinearLayout>

</LinearLayout>

And extract hardcoded strings to res/values/strings.xml

Upvotes: 0

Related Questions