YFeizi
YFeizi

Reputation: 1528

Positioning of an element in a differemt orientation of linearlayout

In my layout i have a LinearLayout with orientation="horizontal"
My issue is that i want to set an ImageView below a textView , is there any way that i can do this? (I know i can do this with RelativeLayout but i don't want to change LinearLayout here)
Its my code:

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.0"
        android:layout_marginBottom="5dp"
        android:background="@drawable/shape_edit_text"
        android:gravity="center_vertical">

    <ImageView
            android:id="@+id/imgFlag"
            android:layout_width="16dp"
            android:layout_height="16dp"
            android:layout_marginLeft="8dp"/>

    <TextView
            android:id="@+id/txtCountries"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.7"
            android:layout_marginRight="1dp"/>

    <EditText
            android:id="@+id/edtPhoneNumber"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:layout_marginLeft="1dp"
            android:hint="@string/phone_number"
            android:inputType="phone"/>
</LinearLayout>

Upvotes: 2

Views: 55

Answers (3)

djanoti
djanoti

Reputation: 303

Either use a new LinearLayout with android:orientation="vertical", or use a RelativeLayou

Upvotes: 0

yummy
yummy

Reputation: 580

Here is a sample what @IIya Kogan described,

<LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1.0"
        android:layout_marginBottom="5dp"
        android:background="@drawable/shape_edit_text"
        android:gravity="center_vertical">
        <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content">
            <ImageView
                android:id="@+id/imgFlag"
                android:layout_width="16dp"
                android:layout_height="16dp"
                android:layout_marginLeft="8dp"/>

            <TextView
                android:id="@+id/txtCountries"
                style="@style/Field.EditText"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="0.7"
                android:layout_marginRight="1dp"/>
        </LinearLayout>

        <EditText
            android:id="@+id/edtPhoneNumber"
            style="@style/Field.EditText"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0.3"
            android:layout_marginLeft="1dp"
            android:hint="@string/phone_number"
            android:inputType="phone"/>
</LinearLayout>

Upvotes: 2

escargot agile
escargot agile

Reputation: 22399

Yes, there's a way to do this. You need to create a layout within a layout and position the two elements in question inside the inner layout. It can be a linear layout with vertical orientation, so the two elements inside it are stacked vertically.

Upvotes: 2

Related Questions