我增加了“菜单图标”的大小,这就是它与“菜单文本”重叠的原因。
因此,为此我使用以下方法“menuAlignment()”管理了它们之间的差距,但不知何故在点击“菜单项”后,“菜单图标”和“菜单文本”之间的差距恢复到以前的状态,即重叠,请帮我解决这个问题。
我的代码如下:
public void menuAlignment()
{
for (int i = 0; i < menuView.getChildCount(); i++) {
final View iconView = menuView.getChildAt(i).findViewById(android.support.design.R.id.icon);
final FrameLayout.LayoutParams layoutParams = (FrameLayout.LayoutParams) iconView.getLayoutParams();
final DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
// set your height here
layoutParams.height = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 27, displayMetrics);
// set your width here
layoutParams.width = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 28, displayMetrics);
layoutParams.gravity=Gravity.CENTER_HORIZONTAL;
layoutParams.setMargins(0,0,0,200);
iconView.setLayoutParams(layoutParams);
// iconView.setPadding(0, 0, 0, 10);
}
}
“ navigationClickListener ”的代码:-
private BottomNavigationView.OnNavigationItemSelectedListener mOnNavigationItemSelectedListener
= new BottomNavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
switch (item.getItemId()) {
case R.id.navigation_jokes_word:
loadFragment(new JokesFragment());
menuAlignment();
return true;
case R.id.navigation_jokes_images:
loadFragment(new ImageJokesFragment());
menuAlignment();
return true;
}
return false;
}
};
牧羊人nacy
largeQ
相关分类