底部导航视图缩小 [英] Bottom Navigation View gets Shrink Down

查看:79
本文介绍了底部导航视图缩小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我从优惠券片段更改为任何其他片段时,我制作了一个带有促销,存储,奖励,优惠券和帐户标签的底部导航视图的应用程序,底部导航视图如图所示缩小了,我尝试过更改布局的宽度,高度并将协调器布局转换为线性布局,但这无济于事。当我仅从主页切换到其他任何选项卡时,就会发生此问题。

I have made an app with bottom navigation view with Promo, Store, Reward, Coupon and Account tabs when I am changing from Coupon fragment to any other fragment, the bottom navigation view gets shrunk down as shown in the image, I tried changing layout width, height and converting coordinator layout to linear layout but it didn't help. The problem is occurring when I'm switching from home to any other tab only.

布局文件activity_main.xml

Layout File 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

Java File 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 到优惠券片段和片段存储

I previously added SearchView to the coupon fragment and fragment store

推荐答案

事实证明,如果您在片段内使用协调器布局和viewpager,将会注意到viewpager稍微扩展了屏幕。只需禁用片段内协调器布局的滚动功能,您会发现底部栏没有缩小。我知道很奇怪,但是可以。

It turns out that if you are using a coordinator layout and viewpager inside a fragment, you will notice that the viewpager extends the screen a bit. Just disable the scroll features of the coordinator layout inside the fragment and you will notice the bottom bar doesn't get shrunk. Weird I know, but it works.

这篇关于底部导航视图缩小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆