AppCompat Snackbar 不以平板电脑为中心

AppCompat Snackbar not centered on tablet

我正在尝试显示一个快餐栏(通过 appcompat)以向用户显示一条消息。它在手机上运行良好,但在平板电脑上我得到

我用来生成小吃店的代码是

Snackbar.make(mHomeContainer, R.string.rate_snackbar, Snackbar.LENGTH_LONG)
        .setAction("Rate", ...)
        .show();

任何有关如何使此小吃店居中的指导将不胜感激

<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <View
        android:id="@+id/status_bar"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:background="@color/main"
        android:elevation="8dp"/>

    <include layout="@layout/toolbar" />

    <RelativeLayout
        android:id="@+id/home_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@+id/main_content"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_alignParentBottom="true" />

        <ListView
            android:id="@+id/home_search_list"
            android:visibility="gone"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="#88000000"/>

    </RelativeLayout>
</LinearLayout>

<include layout="@layout/navigation_list" />

</android.support.v4.widget.DrawerLayout>

您需要使用 CoordinatorLayout 才能实现此目的。这是描述如何做到这一点的 article。此外,您现在可能需要提供要用于非平板电脑与平板电脑的布局文件,以便您可以为手机保留全宽。如果你结合使用 FAB、app bar 和 Snackbar,这也是你需要使用的布局组件。

在设计支持库 v22.2.0 中,Snackbar 的默认重力只是 Gravity.BOTTOM。

在 v22.2.1 中修复了这个问题:https://code.google.com/p/android/issues/detail?id=176383