Search code examples
androidandroid-layoutgrid-layout

LinearLayout inside gridlayout


I have a linearlayout with textview and a imageview inside the gridlayout. I want linearlayout in column1 with the textview and imageview fitting properly in that column of the row. But the image view comes below the textview.

Required result:

enter image description here

My output: enter image description here

Here is my code:

<GridLayout
    android:orientation="horizontal"
    android:rowCount="4"
    android:columnCount="3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/gridLayoutSuburb">
    <LinearLayout
        android:orientation="vertical"
        android:id="@+id/linearLayout1"
        android:layout_row="0"
        android:layout_column="0"
        android:layout_width="0dp"
        android:layout_columnSpan="1"
        android:layout_columnWeight="1"
        android:background="@color/blue">
        <EditText
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:background="@drawable/edittext"
            android:id="@+id/select"
            android:textColor="@color/white"
            android:textSize="@dimen/_16sdp"
            android:textColorHint="@color/white"
            android:editable="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:hint="Select "
            android:paddingLeft="@dimen/_5sdp"
            android:layout_weight="1"
            android:singleLine="true" />
        <ImageView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_alignParentRight="true"
            android:layout_centerInParent="true"
            android:id="@+id/selectImage"
            android:src="@drawable/ic_menu_back" />
    </LinearLayout>
</GridLayout>

What am I doing wrong?


Solution

  • Replace this attribute value of LinearLayout:

    android:orientation="vertical"
    

    To:

    android:orientation="horizontal"