我将从官方的底部导航视图切换到this库。
但我注意到使用此库时,宽度与原始库不同
我错过了什么?
官方图书馆:
AHBottomNavigation:
具有AHBottomNavigation的布局XML:
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mandike.macadamia.views.MainActivity">
<include
android:id="@+id/mToolbarMain"
layout="@layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<com.aurelhubert.ahbottomnavigation.AHBottomNavigation
android:id="@+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_bar_home" />
<fragment
android:id="@+id/mFragmentHome"
class="com.mandike.macadamia.views.HomeFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
<fragment
android:id="@+id/mFragmentNotice"
class="com.mandike.macadamia.views.AnnouncementFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
<fragment
android:id="@+id/mFragmentMailbox"
class="com.mandike.macadamia.views.MailboxFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone" />
<fragment
android:id="@+id/mFragmentMyAccount"
class="com.mandike.macadamia.views.MyAccountFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
具有官方库的布局XML(仅在库行存在差异):
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.mandike.macadamia.views.MainActivity">
<include
android:id="@+id/mToolbarMain"
layout="@layout/toolbar"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.design.widget.BottomNavigationView
android:id="@+id/bottomNavigationView"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="0dp"
android:background="@android:color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:menu="@menu/bottom_bar_home" />
<fragment
android:id="@+id/mFragmentHome"
class="com.mandike.macadamia.views.HomeFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
<fragment
android:id="@+id/mFragmentNotice"
class="com.mandike.macadamia.views.AnnouncementFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
<fragment
android:id="@+id/mFragmentMailbox"
class="com.mandike.macadamia.views.MailboxFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone" />
<fragment
android:id="@+id/mFragmentMyAccount"
class="com.mandike.macadamia.views.MyAccountFragment"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="0dp"
app:layout_constraintTop_toBottomOf="@+id/mToolbarMain"
android:layout_marginRight="0dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginLeft="0dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginBottom="0dp"
app:layout_constraintBottom_toTopOf="@+id/bottomNavigationView"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintHorizontal_bias="0.0"
android:visibility="gone"/>
</android.support.constraint.ConstraintLayout>
最佳答案
终于找到了代码。
在AHBottomNavigation.java中,有些lines会更改每个项目的宽度
if (titleState == TitleState.ALWAYS_SHOW && items.size() > MIN_ITEMS) {
minWidth = resources.getDimension(R.dimen.bottom_navigation_small_inactive_min_width);
maxWidth = resources.getDimension(R.dimen.bottom_navigation_small_inactive_max_width);
}
删除这些行会使该栏的行为类似于官方库。