gpt4 book ai didi

android - snackbar 没有出现在 viewpager 中的 fragment 布局/recyclerview 之上

转载 作者:搜寻专家 更新时间:2023-11-01 07:51:03 25 4
gpt4 key购买 nike

我正在尝试让 snackbar 低于 3 个选项卡。我已经膨胀了一个 fragment 并在其中实现了协调器布局。我无法在选项卡下方的顶部显示 snackbar。并且 getView() 在 float 按钮上方的底部显示 snackbar 和这个代码 How to show Snackbar at top of the screen在我不想要的顶部显示 snackbar 。如何让 snackbar 在 fragment 中显示在标签下方?

代码:

 Snackbar snackbar = Snackbar
.make(coordinatorLayout_snackbar, “Snackbar”, Snackbar.LENGTH_INDEFINITE)
.setAction(“click”, new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e(TAG, "button clicked");
}
});

snackbar.show();

xml:

<?xml version="1.0" encoding="utf-8"?>


<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/frame_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.design.widget.CoordinatorLayout
android:id="@+id/coordinatorLayout_snackbar”
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
</android.support.design.widget.CoordinatorLayout>


<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content">


<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>

</FrameLayout>

最佳答案

您需要将 SwipeRefreshLayout 包裹在 CoordinatorLayout 中,如下所示:

<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:fab="http://schemas.android.com/apk/res-auto"
android:id="@+id/coordinatorLayout_snackbar”
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v4.widget.SwipeRefreshLayout
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical" />
</android.support.v4.widget.SwipeRefreshLayout>

</android.support.design.widget.CoordinatorLayout>

在您当前的布局中,SwipeRefreshLayout 绘制在高度为 0 的 CoordinatorLayout 之上,因为它没有子项且高度设置为 wrap_content。

关于android - snackbar 没有出现在 viewpager 中的 fragment 布局/recyclerview 之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34977107/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com