底部导航视图缩小

2024-01-29

我制作了一个带有促销、商店、奖励、优惠券和帐户选项卡的底部导航视图的应用程序,当我从优惠券片段更改为任何其他片段时,底部导航视图会缩小,如图所示,我尝试更改布局宽度,高度并将协调器布局转换为线性布局,但没有帮助。当我仅从主页切换到任何其他选项卡时,就会出现问题。

布局文件activity_main.xml

<android.support.constraint.ConstraintLayout 
    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:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".activity.MainActivity">

<FrameLayout
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginBottom="56dp"
    android:text="@string/title_home"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<android.support.design.widget.BottomNavigationView
    android:id="@+id/navigation"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_marginEnd="0dp"
    android:layout_marginStart="0dp"
    android:background="@color/white"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintRight_toRightOf="parent"
    app:itemTextColor="@color/selector_bottom_navigation"
    app:itemIconTint="@color/selector_bottom_navigation"
    app:menu="@menu/navigation" />

Java 文件 MainActivity.java

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

    //loading the default fragment
    loadFragment(new PromoFragment());

    //getting bottom navigation view and attaching the listener
    BottomNavigationView navigation = findViewById(R.id.navigation);
    BottomNavigationViewUtils.disableShiftMode(navigation);
    navigation.setOnNavigationItemSelectedListener(this);
}

@Override
public boolean onCreatePanelMenu(int featureId, Menu menu) {
    getMenuInflater().inflate(R.menu.menu_wallet, menu);
    return super.onCreatePanelMenu(featureId, menu);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle item selection
    switch (item.getItemId()) {
        case R.id.menu_wallet1:
            return true;
        case R.id.menu_qrcode:
            Intent intent = new Intent(this, ScannerActivity.class);
            startActivity(intent);
            return true;
        default:
            return super.onOptionsItemSelected(item);
    }
}

@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
    Fragment fragment = null;

    switch (item.getItemId()) {
        case R.id.navigation_promo:
            fragment = new PromoFragment();
            break;

        case R.id.navigation_store:
            fragment = new StoreFragment();
            break;

        case R.id.navigation_reward:
            fragment = new RewardFragment();
            break;

        case R.id.navigation_coupon:
            fragment = new CouponFragment();
            break;

        case R.id.navigation_account:
            fragment = new AccountFragment();
            break;
    }

    return loadFragment(fragment);
}

private boolean loadFragment(Fragment fragment) {
    if (fragment != null) {
        getSupportFragmentManager()
                .beginTransaction()
                .replace(R.id.fragment_container, fragment)
                .commit();
        return true;
    }
    return false;
}

这就是我想说的图片:

我之前添加过SearchView到优惠券片段和片段商店


事实证明,如果您在片段内使用协调器布局和视图分页器,您会注意到视图分页器稍微扩展了屏幕。只需禁用片段内协调器布局的滚动功能,您就会注意到底部栏不会缩小。我知道很奇怪,但它有效。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

底部导航视图缩小 的相关文章

随机推荐