如何在工具栏中对齐 textview 和 tablayout

how to align textview and tablayout in a toolbar

我的工具栏中有文本视图和标签布局。我希望 textview 出现在顶部,tablayout 出现在底部,但无论我如何尝试对齐它们,tablayout 都没有出现在底部 ,而是出现在我的 textview 的右侧

我应该怎么做才能正确对齐它们?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.country.kenya.MainActivity"
android:id="@+id/main_layout"
>

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:id="@+id/mainActivityBar"
    android:layout_alignParentTop="true">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Uhuru Kenyatta"
        android:id="@+id/appname_view"
        android:gravity="top|left" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"

        android:background="@android:color/transparent"
        />

</android.support.v7.widget.Toolbar>

<android.support.v4.view.ViewPager
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/pager"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.country.kenya.MainActivity"
android:layout_below="@+id/mainActivityBar" />

</RelativeLayout>

试试这个

<android.support.v7.widget.Toolbar
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:minHeight="?attr/actionBarSize"
    android:id="@+id/mainActivityBar"
    android:layout_alignParentTop="true">

 <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:gravity="center_vertical"
        android:orientation="vertical"
        >
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:text="Uhuru Kenyatta"
        android:id="@+id/appname_view"
        android:gravity="center" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="fixed"
        app:tabGravity="fill"
        android:background="@android:color/transparent"
        />
    </LinearLayout>
</android.support.v7.widget.Toolbar>

如有问题请留言

祝你好运!