底部导航视图缩小
Bottom Navigation View gets Shrink Down
我制作了一个带有促销、商店、奖励、优惠券和帐户选项卡的底部导航视图的应用程序,当我从优惠券片段更改为任何其他片段时,底部导航视图缩小,如图所示,我尝试更改布局宽度、高度并将协调器布局转换为线性布局,但没有帮助。当我仅从主页切换到任何其他选项卡时出现问题。
布局文件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
添加到优惠券片段和片段商店
事实证明,如果您在片段内使用协调器布局和 viewpager,您会注意到 viewpager 稍微扩展了屏幕。只需在片段内禁用协调器布局的滚动功能,您就会注意到底部栏没有缩小。我知道这很奇怪,但它确实有效。
我在 CoordinatorLayout 中添加 android:fitsSystemWindows="false" 并且有效
在您的片段 xml 中找到 android:fitsSystemWindows="true"
并删除此行
或将其更改为 android:fitsSystemWindows="false"
。你的问题就迎刃而解了。
我制作了一个带有促销、商店、奖励、优惠券和帐户选项卡的底部导航视图的应用程序,当我从优惠券片段更改为任何其他片段时,底部导航视图缩小,如图所示,我尝试更改布局宽度、高度并将协调器布局转换为线性布局,但没有帮助。当我仅从主页切换到任何其他选项卡时出现问题。
布局文件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
添加到优惠券片段和片段商店
事实证明,如果您在片段内使用协调器布局和 viewpager,您会注意到 viewpager 稍微扩展了屏幕。只需在片段内禁用协调器布局的滚动功能,您就会注意到底部栏没有缩小。我知道这很奇怪,但它确实有效。
我在 CoordinatorLayout 中添加 android:fitsSystemWindows="false" 并且有效
在您的片段 xml 中找到 android:fitsSystemWindows="true"
并删除此行
或将其更改为 android:fitsSystemWindows="false"
。你的问题就迎刃而解了。