Как переместить LinearLayout в правую часть панели инструментов - PullRequest
0 голосов
/ 21 января 2020

Я пытаюсь добавить на панель инструментов TextView и Spinner для осуществления изменения языка оттуда. Проблема в том, что я добавил LinearLayout к toolbar, но мне не удалось переместить его на правую сторону, чтобы оно не перебивало название упражнения или не оставалось рядом с ним.

Прямо сейчас LinearLayout установлено так (+ где я хочу, чтобы это было):

enter image description here

. xml код:

<com.google.android.material.appbar.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:theme="@style/AppTheme.AppBarOverlay">

    <androidx.appcompat.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="?attr/actionBarSize"
        android:background="?attr/colorPrimary"
        app:popupTheme="@style/AppTheme.PopupOverlay">
    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content">
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/limba"
        android:textColor="@color/white"
        android:textSize="15sp"
        android:layout_gravity="center"/>
    <Spinner
        android:layout_marginLeft="5dp"
        android:id="@+id/spinner_limba"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
    </LinearLayout>
    </androidx.appcompat.widget.Toolbar>

</com.google.android.material.appbar.AppBarLayout> 

И вот результат:

enter image description here

Я пытаюсь добиться чего-то вроде:

enter image description here

Я добился этого, установив android:paddingLeft, но это не будет работать на всех устройствах одинаково, поэтому я ищу другое решение.

I попытался добавить gravity, но это не изменило мой макет.

Ответы [ 2 ]

2 голосов
/ 21 января 2020

добавить android: layout_gravity = "right" в линейном макете.

  <LinearLayout
    android:orientation="horizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="right">
 </LinearLayout>
0 голосов
/ 21 января 2020

Оберните LinearLayout с помощью RelativeLayout и предоставьте

android: layout_alignParentRight = "true"

свойство LinearLayout.

Попробуйте это

1010 *
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...