gpt4 book ai didi

android - 如何在 Tab 布局中仅将 Floating Action Button 专门放置在一个 fragment 上

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:07:53 25 4
gpt4 key购买 nike

我试图实现以下目标但没有成功。我有两个 Material 设计滑动选项卡。我使用了 this library 'com.oguzdev:CircularFloatingActionMenu:1.0.2' 实现 FAB,但是当我将选项卡滑动到第二个选项卡时,FAB 仍附加到新 fragment 。

我想在第二个 Fragment 上隐藏 FAB。有办法实现吗?

最佳答案

这是我针对类似问题所做的。我为 fragment 声明了一个协调器布局。在该协调器布局内,如您在图像中所见,我声明了一个我使用的 recyclerView,并在其下方声明了我的 float 操作按钮。

在此之后,我在 onCreateView fragment 方法中为 float 操作按钮扩充了布局。

这是我的 XML 文件代码:

<android.support.design.widget.CoordinatorLayout
android:id="@+id/main_content"
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="match_parent"
android:focusableInTouchMode="true">

<EditText
android:id="@+id/search_string"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_margin="5dp"
android:layout_marginTop="50dp"
android:hint="Search Keyword"
android:drawableLeft="@drawable/search"
android:gravity="left" >
</EditText>

<android.support.v7.widget.RecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/photo_recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="50dp"
android:scrollbars="vertical"/>

<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_margin="@dimen/fab_margin"
android:src="@drawable/ic_action_name6" />
</android.support.design.widget.CoordinatorLayout>

这是我的 Java 文件代码:

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_photo_list, container, false);

FloatingActionButton fab = (FloatingActionButton) view.findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Photo photo = new Photo();
PhotoLab.get(getActivity()).addPhoto(photo);
Intent intent = PhotoPagerActivity.newIntent(getActivity(), photo.getId());
startActivity(intent);
/*Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();*/
}
});

mSearchString=(EditText) view.findViewById(R.id.search_string);
mPhotoRecyclerView = (RecyclerView) view.findViewById(R.id.photo_recycler_view);
mPhotoRecyclerView.setLayoutManager(new GridLayoutManager(getActivity(), 3));

updateUI();
return view;
}

关于android - 如何在 Tab 布局中仅将 Floating Action Button 专门放置在一个 fragment 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30926528/

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