Android Relative layout: ToLeftOf go view

I have a relative layout where I have a TextView

spinner on the left and a spinner on the right. Also I need an error image to show if the user has chosen the wrong option.

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

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="40dp"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:gravity="center_vertical"
            android:text="@string/some_text"/>
        <Spinner
            android:id="@+id/spinner"
            android:layout_width="74dp"
            android:layout_height="40dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@+id/err"/>
        <ImageView

            android:id="@+id/err"
            android:layout_centerVertical="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:src="@drawable/ic_error"/>
    </RelativeLayout>

      

I want my spinner to be on the right aligned when the error is not showing (visibility = GONE) and move it to the left of the error image when the error is visible. How should I do it? Now it just ignores this:

android:layout_toLeftOf="@+id/err"

      

EDIT: thanks, I corrected the typo, but that's not the cause of the problem.

+3


source to share


3 answers


Perhaps you want something like this:

<LinearLayout 
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:gravity="center_vertical|right"
     android:layout_alignParentRight="true"
     android:orientation="horizontal" >

     <Spinner
        android:id="@+id/spinner"
        android:layout_width="74dp"
        android:layout_height="40dp" />

     <ImageView
        android:id="@+id/err"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/ic_error"/>
</LinearLayout>

      



EDIT: Just place Spinner

and ImageView

inside LinearLayout

like this one.

+3


source


I think you have a typo in your code. It should be android:layout_toLeftOf="@+id/err"

insteadandroid:layout_toLeftOf="@id/err"



0


source


Make 2 Spinners and make one of them invisible each time

-3


source







All Articles