代码之家  ›  专栏  ›  技术社区  ›  Gnzlt

小吃店内部布局

  •  0
  • Gnzlt  · 技术社区  · 9 年前

    是否可以在布局中显示Snackbar消息,例如在RelativeLayout中显示,而不是在屏幕底部显示?

    我已经尝试使用RelativeLayout的引用视图,但它不起作用。

    Snackbar.make(relativeLayoutView, snackbarText, Snackbar.LENGTH_LONG).show();
    
    2 回复  |  直到 9 年前
        1
  •  2
  •   Amarjit    9 年前

    您可以通过创建新布局来完成此操作 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>
    
        2
  •  0
  •   Vadim Kotov First Zero    7 年前

    我认为你不能在屏幕上的任何地方展示小吃条,只能在底部展示。根据标准,它应该在底部。

    根据文件所述,

    “小吃条提供关于操作的轻量级反馈。在移动设备上,它们在屏幕底部显示一条简短的消息,在大型设备上,则显示在左下方。”

    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?