gpt4 book ai didi

android - 从带有折叠工具栏的选项卡切换时 Bottomnavigationview 隐藏

转载 作者:太空宇宙 更新时间:2023-11-03 10:35:52 27 4
gpt4 key购买 nike

我有一个 MainActivity XML,其中包含一个带有 5 个选项卡的 bottomNavigationView(栏)。每个选项卡调用不同的 fragment 。从 XML 中带有折叠工具栏的 fragment (图片中标记为 A)切换到带有普通 fragment (图片中标记为 B)的 fragment 会导致 bottomNavigationView(栏)部分隐藏在屏幕之外。

有没有办法避免这种情况?

带有包含折叠工具栏 fragment 的屏幕。

Link: screen with fragment containing collapsing toolbar

带有普通 fragment 的另一个选项卡的屏幕。

Link: screen of another tab with a plain fragment

包含折叠工具栏代码的 fragment 类

 public class Profile extends Fragment {

public Profile() {

}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
//setHasOptionsMenu(true);

View rootView = inflater.inflate(R.layout.fragment_profile, container, false);

Toolbar toolbar = rootView.findViewById(R.id.toolbar);

AppCompatActivity activity = (AppCompatActivity) getActivity();
activity.setSupportActionBar(toolbar);
activity.getSupportActionBar().setDisplayHomeAsUpEnabled(true);

CollapsingToolbarLayout collapsingToolbar = rootView.findViewById(R.id.collapsing_toolbar);
collapsingToolbar.setTitle("test");

return rootView;
}

包含折叠工具栏代码的相应 xml

<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">

<android.support.v7.widget.RecyclerView
android:id="@+id/recycler"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />

<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="180dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark">

<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed">

<ImageView
android:id="@+id/header"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/ani_dog_one"
android:contentDescription="whut"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
app:layout_collapseMode="parallax" />

<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>

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

普通 fragment 类

public class Review extends Fragment {

public Review() {
}


@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_review, container, false);
//setHasOptionsMenu(true);
return rootView;
}

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.search_bar_menu, menu);
super.onCreateOptionsMenu(menu, inflater);
}

普通 fragment 类的 XML 只包含一个普通的 FrameLayout

主要 Activity

public class MainActivity extends AppCompatActivity {

private Intent intent;

private android.support.v4.app.FragmentManager manager;
private android.support.v4.app.FragmentTransaction transaction;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

manager = getSupportFragmentManager();
transaction = manager.beginTransaction();

Discover discoverFragment = new Discover();
transaction.replace(R.id.container, discoverFragment, discoverFragment.getTag()).commit();

setupBottomNavigationView();

}

private void setupBottomNavigationView() {

BottomNavigationViewEx bottomNavigationViewEx = (BottomNavigationViewEx) findViewById(R.id.bottom_navigation);
BottomNavigationViewHelper.setupBottomNavigationView(bottomNavigationViewEx);
BottomNavigationViewHelper.enableNavigation(this, bottomNavigationViewEx);

}

public void goToOptions(MenuItem menu) {

intent = new Intent(this, Options.class);
overridePendingTransition(R.anim.left_in, R.anim.right_out);
startActivity(intent);
}

MainActivity 的 XML

    <LinearLayout 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"
android:orientation="vertical"
tools:context="com.example.android.project_qwer.MainActivity">

<!-- main fragments goes here -->
<FrameLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">

</FrameLayout>

<!-- bottom navigation view -->
<com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx
android:id="@+id/bottom_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:background="?android:attr/windowBackground"
app:menu="@menu/bottom_navigation_menu" >

</com.ittianyu.bottomnavigationviewex.BottomNavigationViewEx>

</LinearLayout>

最佳答案

尝试删除

android:fitsSystemWindows="true"

在您的 CollapsingToolbarLayout 上。

关于android - 从带有折叠工具栏的选项卡切换时 Bottomnavigationview 隐藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267937/

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