1

I am trying to align the ImageView inside the Autocomplete textView. I did this but the ImageView appears below the AutocomplteTextView. I changed the width of textView but same problem arises. I am looking for something like this:

Is there any way I can achieve this?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context="com.kalpu.placepick.SearchFragment">


    <LinearLayout
        android:id="@+id/linearLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">


        <AutoCompleteTextView
            android:id="@+id/acTextView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:completionHint="From"
            android:dropDownHeight="match_parent"
            android:hint="From"
            android:visibility="visible"
            />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@id/image"
            android:padding="5dp"
            android:layout_alignTop="@id/acTextView1"
            android:layout_alignBottom="@id/acTextView1"
            android:layout_alignRight="@id/acTextView1"
            android:src="@mipmap/ic_arrow_drop_down"

            />


        <AutoCompleteTextView
            android:id="@+id/acTextView2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/acTextView1"
            android:completionHint="From"
            android:dropDownHeight="match_parent"
            android:hint="Intermediate (Optional) "
            android:paddingTop="50dp"
            android:visibility="visible" />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@id/image"
            android:padding="5dp"
            android:layout_alignTop="@id/acTextView2"
            android:layout_alignBottom="@id/acTextView2"
            android:layout_alignRight="@id/acTextView1"
            android:src="@mipmap/ic_arrow_drop_down"

            />
 </LinearLayout>
</RelativeLayout>

3 Answers3

1

Try below code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<RelativeLayout
    android:id="@+id/relativeLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <AutoCompleteTextView
        android:id="@+id/acTextView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="From"
        android:dropDownHeight="match_parent"
        android:hint="From"
        android:padding="20dp"
        android:visibility="visible"
        />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@id/image"
        android:layout_alignParentRight="true"
        android:src="@mipmap/your_image"
        />
</RelativeLayout>


<RelativeLayout
    android:id="@+id/relativeLayout2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:paddingTop="20dp">

    <AutoCompleteTextView
        android:id="@+id/acTextView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:completionHint="From"
        android:padding="20dp"
        android:dropDownHeight="match_parent"
        android:hint="Intermediate (Optional) "
        android:visibility="visible" />
    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@id/image"
        android:src="@mipmap/your_image"
        android:layout_alignParentRight="true"

        />
</RelativeLayout></LinearLayout>
Yogi Bear
  • 603
  • 8
  • 22
1

Try this bro:

 <FrameLayout
    android:id="@+id/search"
    android:layout_width="300dp"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true">

    <android.support.v7.widget.AppCompatAutoCompleteTextView
        android:id="@+id/autoCompleteSearch"
        android:layout_width="260dp"
        android:layout_height="40dp"
        android:paddingLeft="10dp"
        android:background="@android:color/transparent"
        android:hint="Search by Event"
        android:inputType="textAutoComplete"
        android:textSize="14sp"
        android:visibility="visible" />

    <ImageView
        android:id="@+id/searchBu"
        android:layout_width="40dp"
        android:layout_height="40dp"
        android:layout_gravity="center_vertical|right"
        android:padding="10dp"
        android:src="@mipmap/ic_arrow_drop_down" />

</FrameLayout>`
Saber Elharti
  • 93
  • 1
  • 5
0

This is because you have placed the imageView below the AutoCompleteTextView in the xml. You will have to create a custom dropdown layout for images to appear in it. You could check this library https://github.com/koush/ion

Amrith M
  • 56
  • 1
  • 6