我的菜单中有项目,但它本身在折叠的工具栏中。我想要做的是,当折叠的工具栏折叠时,菜单项位于顶部,而当折叠的工具栏完全展开时,菜单项在折叠工具栏的底部(例如,在带有一个)。这是:我的XML文件代码
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.appbar.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="@color/white"
app:elevation="0dp">
<com.google.android.material.appbar.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:expandedTitleGravity="center"
app:layout_scrollFlags="scroll|snap|exitUntilCollapsed"
app:title="Messages">
<androidx.appcompat.widget.AppCompatImageView
android:layout_width="match_parent"
android:layout_height="220dp" />
<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize">
</androidx.appcompat.widget.Toolbar>
</com.google.android.material.appbar.CollapsingToolbarLayout>
</com.google.android.material.appbar.AppBarLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
我的Java代码:
public class ChatFragment extends Fragment {
@Nullable
@Override
public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//Creation de la view qui va inflate l'affichage
View view = inflater.inflate(R.layout.fragment_chat, container, false);
Toolbar toolbar = view.findViewById(R.id.toolbar);
toolbar.inflateMenu(R.menu.messages_menu);
toolbar.setOverflowIcon(getDrawable(getContext(), R.drawable.ic_more_horiz));
return view;
}
}
以下是我的应用中发生的情况的屏幕截图:
如您所见,我的项目和工具栏在折叠时消失,在完全展开时显示。
这是我想做的(我的目标)的屏幕截图:
谢谢您的帮助
将工具栏的layout_gravity属性设置为底部