是否可以在布局中显示一条Snackbar消息,比如在RelativeLayout中显示它,而不是在屏幕底部显示它?
我尝试使用RelativeLayout的引用视图,但它不起作用。
Snackbar.make(relativeLayoutView, snackbarText, Snackbar.LENGTH_LONG).show();发布于 2015-09-14 08:49:45
我不认为你可以在屏幕上的任何地方显示一个零食条,但只能显示在底部。根据标准,它应该在底部。
如文件所述,
“Snackbar提供有关操作的轻量级反馈。它们在屏幕底部的移动设备上显示简短的信息,在较大的设备上显示左下角的信息。”
https://developer.android.com/reference/android/support/design/widget/Snackbar.html
如果你还想这么做,退房,
How can you adjust Android SnackBar to a specific position on screen
How do I change an Android Snackbar's initial alignment from bottom to top?
发布于 2015-09-14 09:26:26
您可以通过在相对布局中创建一个新的布局CoordinatorLayout并将自定义的宽度和高度设置为CoordinatorLayout布局来做到这一点。
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="100dip">
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="16dp"
android:src="@drawable/add"
app:layout_behavior="com.demotest.FloatingActionButtonBehavior" />
</android.support.design.widget.CoordinatorLayout>
</RelativeLayout>https://stackoverflow.com/questions/32560596
复制相似问题