how to change the dropdown height in spinner

后端 未结 11 1628
粉色の甜心
粉色の甜心 2021-02-05 11:20

i tried a lot to change the dropdown item height of spinner.. but i couldn\'t get a good solution.. plz help me guys..

here is a code loginactivityview.xml



        
11条回答
  •  滥情空心
    2021-02-05 12:08

    Got stuck in same problem.Found following solution to be working for me:

     if (Build.VERSION.SDK_INT > Build.VERSION_CODES.LOLLIPOP_MR1) {
            setSpinnerDropDownHeight()
        } else {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
                mBinding?.included?.spinn?.getViewTreeObserver()?.addOnGlobalLayoutListener(object : ViewTreeObserver.OnGlobalLayoutListener {
                    @RequiresApi(Build.VERSION_CODES.JELLY_BEAN)
                    override fun onGlobalLayout() {
                        mBinding?.included?.spinn?.dropDownVerticalOffset = mBinding?.included?.spinn?.getDropDownVerticalOffset()!! + mBinding?.included?.spinn?.getHeight()!!
                        mBinding?.included?.spinn?.viewTreeObserver!!.removeOnGlobalLayoutListener(this)
                    }
                })
    
                mBinding?.included?.spinn?.dropDownVerticalOffset = 10
            }
        }
    

    Hope it helps someone!!!!

    Thanks

提交回复
热议问题