How to show my Spinner to right of Toolbar
Asked Answered
S

1

7

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?

Shull answered 5/8, 2015 at 12:36 Comment(8)
Try android:layout_gravity="right" for spinnerCsc
@Csc spinner is not showing this in auto suggestShull
Din't understand your commentCsc
check the updated question @CscShull
tried it myself. looks like s27.postimg.org/4uz1ssatf/image.png. just had layout_gravity as mentionedCsc
Added it to code and worked, thnx @Raghunandan. but why it didn't showed at firstShull
Let us continue this discussion in chat.Csc
it's work, thank you @CscChive
C
4

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>
Cortney answered 4/4, 2016 at 14:55 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.