karan
karan

Reputation: 8853

How to show my Spinner to right of Toolbar

my Layout looks like below enter image description here

You can see spinner added to my toolbar, but what I want is to make it right align, show it to most right of toolbar.

below is the xml code I used

<LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:orientation="vertical" >

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_height="0dp"
            android:layout_width="match_parent"
            android:layout_weight="1"
            android:elevation="4dp"
            android:gravity="right"                          //gravity set to right
            android:background = "@color/color_toolbar"
        >
             <Spinner
                android:id="@+id/spinner_category"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content" />
        </android.support.v7.widget.Toolbar> 
   </LinearLayout>

spinner is not showing android:layout_gravity enter image description here I tried setting gravity to right but it doesn't work. how can I do this?

Upvotes: 7

Views: 2170

Answers (1)

Sandeep
Sandeep

Reputation: 3344

I had the same issue. I have fixed the alignment issue based on the comments of question. So keeping the answer here to help someone directly.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:minHeight="?attr/actionBarSize"
    android:background="?attr/colorPrimary">
    <Spinner
        android:id="@+id/toolbar_spinner"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:visibility="visible"
        android:layout_gravity="right"/>
</android.support.v7.widget.Toolbar>

Upvotes: 4

Related Questions