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