I have Spinner and TextView in my LinearLayour.
I am trying to align Spinner and TextView vertically to center both on the same line:

This is my XML for this element:
<LinearLayout
android:id="@+id/dropdownlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center" />
<TextView
android:id="@+id/ok1"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:background="@drawable/white_box"
android:gravity="center"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:text="@string/ok"
android:textColor="@android:color/black"
android:textSize="@dimen/normale" />
</LinearLayout>
I tried this code, the same result:
<RelativeLayout
android:id="@+id/dropdownlayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Spinner
android:id="@+id/spinner1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:gravity="center" />
<TextView
android:id="@+id/ok1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/spinner1"
android:background="@drawable/white_box"
android:gravity="center"
android:padding="10dp"
android:text="@string/ok"
android:textColor="@android:color/black"
android:textSize="@dimen/normale" />
</RelativeLayout>
source
share