How to show my counter to the right of the toolbar

my layout looks like below enter image description here

You can see that the spinner has been added to my toolbar, but I want it to align to the right, showing it to the right of the 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 does not show android:layout_gravity enter image description here I tried to set gravity to the right, but that will not work. How can i do this?

+5
source share
1 answer

I had the same problem. I fixed the alignment problem based on the comments of the question. So keep 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> 
+2
source

All Articles