在 android 中将视图与 TabLayout 的右侧对齐

Align a View to Right of TabLayout in android

我想在 activity 中显示 Tablayout,然后 TabLayout 想显示右对齐的 ImageButton。我为此使用以下布局,但选项卡未正确显示,最后一个选项卡被裁剪。我想在 TabLayout 之后显示可滚动的选项卡和一个 ImageButton。

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_marginLeft="@dimen/margin_5dp"
android:layout_marginStart="@dimen/margin_5dp"
android:layout_marginRight="@dimen/margin_5dp"
android:layout_marginEnd="@dimen/margin_5dp"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:tabMode="scrollable"
    app:tabGravity="center"
    android:background="@color/gray_background"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true" />

<ImageButton
    android:background="@color/gray_background"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:scaleType="center"
    android:id="@+id/add_sticker_store"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginLeft="@dimen/margin_5dp"
    android:src="@drawable/ic_action_new"/>


<android.support.v4.view.ViewPager
    android:layout_below="@id/tabs"
    android:id="@+id/viewpager"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/gray_background"
    android:layout_alignParentBottom="true"/>

<View
    android:layout_width="match_parent"
    android:layout_height="2dp"
    android:layout_below="@id/tabs"
    android:background="@color/white"/>

请查看裁剪最后一个标签的视图的屏幕截图。如果有人知道如何实现这一点,请提供帮助。

请帮忙,非常感谢。

在 TabLayout 和 ImageButton 之间添加规则。

<ImageButton
    android:background="@color/gray_background"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:scaleType="center"
    android:id="@+id/add_sticker_store"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginLeft="@dimen/margin_5dp"
    android:src="@drawable/ic_action_new"/>

<android.support.design.widget.TabLayout
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:tabMode="scrollable"
    app:tabGravity="center"
    android:background="@color/gray_background"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_toLeftOf="@+id/add_sticker_store" />

我认为这可以解决您的问题

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_marginLeft="5dp"
    android:layout_marginStart="5dp"
    android:layout_marginRight="5dp"
    android:layout_marginEnd="5dp"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:id="@+id/ll">

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_weight="9"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            app:tabMode="scrollable"
            app:tabGravity="center"
            android:background="@color/colorAccent"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true" />

        <ImageButton
            android:layout_weight="1"
            android:background="@color/colorAccent"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:scaleType="center"
            android:id="@+id/add_sticker_store"
            android:layout_alignParentRight="true"
            android:layout_alignParentEnd="true"
            android:layout_marginLeft="5dp"/>


    </LinearLayout>


    <android.support.v4.view.ViewPager
        android:layout_below="@id/ll"
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/colorAccent"
        android:layout_alignParentBottom="true"/>

    <View
        android:layout_width="match_parent"
        android:layout_height="2dp"
        android:layout_below="@id/ll"
        android:background="@color/colorPrimaryDark"/>

    </RelativeLayout>