Android – align the underlined spinners in the same line next to the edit text

I have an EditText and an underlined spinner. I try to set the spinner next to EditText on the same line. Please help me. Spinner is always slightly higher than EditText

 <RelativeLayout
        android:id="@+id/relativeLayout4"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/relativeLayout0"

        android:layout_alignParentLeft="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp">

        <ImageView
            android:id="@+id/ivRupee"
            android:src="@drawable/ic_rupee_new"
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:layout_centerVertical="true"  />
        <ImageView
            android:id="@+id/fake"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"/>


        <EditText
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:id="@+id/editText"
            android:layout_toRightOf="@+id/ivRupee"
            android:layout_alignRight="@+id/fake"
            android:layout_marginRight="5dp"/>
        <Spinner

            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/editText"
            android:gravity="center"
            android:layout_alignLeft="@+id/fake"
            android:layout_alignParentRight="true"
            android:id="@+id/spinner2"
            style="@style/Widget.AppCompat.Spinner.Underlined"/>

    </RelativeLayout>

I need something like this:

I encountered the same problem. I solved this problem by deleting style = "@ style / widget. Appcompat. Spinner. Understood" and set a background for spinner: Android = background = "@ drawable / custom_spinner_background"

custom_ spinner_ background.xml:

<?xml version="1.0" encoding="utf-8"?>
<inset xmlns:android="http://schemas.android.com/apk/res/android"
    android:insetBottom="8dp"
    android:insetLeft="4dp"
    android:insetRight="4dp"
    android:insetTop="4dp">
    <selector>
        <item
            android:state_checked="false"
            android:state_pressed="false">
            <layer-list>
                <item
                    android:left="-8dp"
                    android:right="-8dp"
                    android:top="-8dp">
                    <shape android:shape="rectangle">
                        <stroke
                            android:width="1dp"
                            android:color="@color/colorAccent" />
                        <padding android:bottom="4dp" />
                    </shape>
                </item>
            </layer-list>
        </item>
        <item>
            <layer-list>
                <item
                    android:left="-8dp"
                    android:right="-8dp"
                    android:top="-8dp">
                    <shape android:shape="rectangle">
                        <stroke
                            android:width="2dp"
                            android:color="@color/colorAccent" />
                        <padding android:bottom="4dp" />
                    </shape>
                </item>
            </layer-list>
        </item>
    </selector>
</inset>

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>