如何在Android(Kotlin)的中心设置BottomNavigationView项

时间:2019-03-03 05:30:49

标签: android kotlin bottomnavigationview layout-gravity

我的BottomNavigationView中有3个项目,我用以下代码调整了每个项目的大小:

  val menuView = bottomNavigation.getChildAt(0) as BottomNavigationMenuView

        for (i in 0 until menuView.childCount) {
            val iconView = menuView.getChildAt(i).findViewById<View>(android.support.design.R.id.icon)
            val layoutParams = iconView.layoutParams
            val displayMetrics = resources.displayMetrics
            layoutParams.height = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20f, displayMetrics).toInt()
            layoutParams.width = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 20f, displayMetrics).toInt()
            iconView.layoutParams = layoutParams

        }

现在此项目不在BottomNavigationView的中心。可以请我用Kotlin方法将每个项目放在BottomNavigationView的中心吗?

1 个答案:

答案 0 :(得分:0)

尝试下面的事情

解决方案1 ​​

ctypes

解决方案2

如果您正在使用最新的支持库,则可以使用此解决方案。 在xml中添加此行

elif _os.name == 'posix' and _sys.platform == 'cygwin':
    # c:\Windows\System32\kernel32.dll
    kernel32_name = '/proc/cygdrive/c/Windows/System32/kernel32.dll'
    kernel32 = CDLL(kernel32_name)
    _GetSystemPowerStatus = kernel32.GetSystemPowerStatus


$ python3.7 GetSystemPowerStatus.py
Traceback (most recent call last):
  File "GetSystemPowerStatus.py", line 82, in <module>
    result, systemPowerStatus = GetSystemPowerStatus()
  File "GetSystemPowerStatus.py", line 66, in GetSystemPowerStatus
    kernel32 = CDLL(kernel32_name)
  File "/usr/lib/python3.7/ctypes/__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: Invalid argument