Skip to content

Fixed: https://github.com/roughike/BottomBar/issues/371 #866

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
77 changes: 28 additions & 49 deletions bottom-bar/src/main/java/com/roughike/bottombar/BottomBar.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.view.ViewOutlineProvider;
import android.view.ViewParent;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;

import java.util.List;
Expand Down Expand Up @@ -65,7 +64,6 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie
private BatchTabPropertyApplier batchPropertyApplier;
private int primaryColor;
private int screenWidth;
private int tenDp;
private int maxFixedItemWidth;

// XML Attributes
Expand All @@ -87,7 +85,7 @@ public class BottomBar extends LinearLayout implements View.OnClickListener, Vie

private View backgroundOverlay;
private ViewGroup outerContainer;
private ViewGroup tabContainer;
private BottomBarTabContainer tabContainer;

private int defaultBackgroundColor = Color.WHITE;
private int currentBackgroundColor;
Expand Down Expand Up @@ -185,7 +183,6 @@ private void init21(Context context) {
private void populateAttributes(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
primaryColor = MiscUtils.getColor(getContext(), R.attr.colorPrimary);
screenWidth = MiscUtils.getScreenWidth(getContext());
tenDp = MiscUtils.dpToPixel(getContext(), 10);
maxFixedItemWidth = MiscUtils.dpToPixel(getContext(), 168);

TypedArray ta = context.getTheme()
Expand Down Expand Up @@ -266,7 +263,7 @@ private void initializeViews() {

backgroundOverlay = rootView.findViewById(R.id.bb_bottom_bar_background_overlay);
outerContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_outer_container);
tabContainer = (ViewGroup) rootView.findViewById(R.id.bb_bottom_bar_item_container);
tabContainer = (BottomBarTabContainer) rootView.findViewById(R.id.bb_bottom_bar_item_container);
shadowView = findViewById(R.id.bb_bottom_bar_shadow);
}

Expand Down Expand Up @@ -394,28 +391,43 @@ private void resizeTabsToCorrectSizes(BottomBarTab[] tabsToAdd) {

inActiveShiftingItemWidth = (int) (proposedItemWidth * 0.9);
activeShiftingItemWidth = (int) (proposedItemWidth + (proposedItemWidth * ((tabsToAdd.length - 1) * 0.1)));
int height = Math.round(getContext().getResources()
int tabHeight = Math.round(getContext().getResources()
.getDimension(R.dimen.bb_height));

for (BottomBarTab tabView : tabsToAdd) {
ViewGroup.LayoutParams params = tabView.getLayoutParams();
params.height = height;
int tabWidth;
BottomBarTab tabView;
ViewGroup.LayoutParams params;
boolean isParamsChanged;
for (int i = 0; i < tabsToAdd.length; i++) {
tabView = tabsToAdd[i];
params = tabView.getLayoutParams();

if (isShiftingMode()) {
if (tabView.isActive()) {
params.width = activeShiftingItemWidth;
tabWidth = activeShiftingItemWidth;
} else {
params.width = inActiveShiftingItemWidth;
tabWidth = inActiveShiftingItemWidth;
}
} else {
params.width = proposedItemWidth;
tabWidth = proposedItemWidth;
}

if (tabView.getParent() == null) {
tabContainer.addView(tabView);
if (params.height != tabHeight || params.width != tabWidth) {
params.height = tabHeight;
params.width = tabWidth;
isParamsChanged = true;
} else {
isParamsChanged = false;
}

tabView.setLayoutParams(params);
if (tabView.getParent() == null) {
if (ViewCompat.isInLayout(this)) {
tabContainer.addViewInLayout(tabView, i, params);
} else {
tabContainer.addView(tabView, i, params);
}
} else if (isParamsChanged) {
tabView.setLayoutParams(params);
}
}
}

Expand Down Expand Up @@ -761,8 +773,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
resizeTabsToCorrectSizes(currentTabs);
}

updateTitleBottomPadding();

if (isShy()) {
initializeShyBehavior();
}
Expand All @@ -773,37 +783,6 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
}
}

private void updateTitleBottomPadding() {
if (isIconsOnlyMode()) {
return;
}

int tabCount = getTabCount();

if (tabContainer == null || tabCount == 0 || !isShiftingMode()) {
return;
}

for (int i = 0; i < tabCount; i++) {
BottomBarTab tab = getTabAtPosition(i);
TextView title = tab.getTitleView();

if (title == null) {
continue;
}

int baseline = title.getBaseline();
int height = title.getHeight();
int paddingInsideTitle = height - baseline;
int missingPadding = tenDp - paddingInsideTitle;

if (missingPadding > 0) {
title.setPadding(title.getPaddingLeft(), title.getPaddingTop(),
title.getPaddingRight(), missingPadding + title.getPaddingBottom());
}
}
}

private void initializeShyBehavior() {
ViewParent parent = getParent();

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.roughike.bottombar;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;

public class BottomBarTabContainer extends LinearLayout {

public BottomBarTabContainer(Context context) {
super(context);
}

public BottomBarTabContainer(Context context, AttributeSet attrs) {
super(context, attrs);
}

public BottomBarTabContainer(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

@SuppressWarnings("NewApi")
public BottomBarTabContainer(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

@Override
public boolean addViewInLayout(View child, int index, ViewGroup.LayoutParams params) {
return super.addViewInLayout(child, index, params);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:visibility="invisible" />

<LinearLayout
<com.roughike.bottombar.BottomBarTabContainer
android:id="@+id/bb_bottom_bar_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
android:layout_height="match_parent"
android:visibility="invisible"/>

<LinearLayout
<com.roughike.bottombar.BottomBarTabContainer
android:id="@+id/bb_bottom_bar_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
android:layout_height="match_parent"
android:visibility="invisible" />

<LinearLayout
<com.roughike.bottombar.BottomBarTabContainer
android:id="@+id/bb_bottom_bar_item_container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
android:id="@+id/bb_bottom_bar_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="10dp"
android:textAppearance="@style/BB_BottomBarItem_Shifting.TitleAppearance"
android:visibility="gone"
style="@style/BB_BottomBarItem_TitleStyle"/>
Expand Down