android – AppCompat Snackbar不以平板电脑为中心

我正在尝试显示一个快餐栏(通过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的组合,这也是您需要使用的布局组件.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...