gpt4 book ai didi

android - 底部导航 View 缩小

转载 作者:行者123 更新时间:2023-12-04 01:19:05 25 4
gpt4 key购买 nike

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

布局文件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;
}

这就是我的意思:

enter image description here

我之前将 SearchView 添加到优惠券 fragment 和 fragment 存储中

最佳答案

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

关于android - 底部导航 View 缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53552216/

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