how to change the dropdown height in spinner

后端 未结 11 1647
粉色の甜心
粉色の甜心 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:00

    //This might also help:

        adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, dataForAdapter) {
    
    
            @Override
            public View getDropDownView(int position, View convertView, ViewGroup parent) {
                View v = super.getView(position, convertView, parent);
                v.setMinimumHeight((int) (40*cx.getResources().getDisplayMetrics().density));
                v.setBackgroundColor(Color.rgb(222, 222, 222));
    
    
                return v;
            }
    
        };
    
    0 讨论(0)
  • 2021-02-05 12:03

    Override method in ArrayAdapter class

    @Override
    public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent) {
        View view = super.getDropDownView(position, convertView, parent);
        view.getLayoutParams().height = 50;
        return view;
    }
    
    0 讨论(0)
  • 2021-02-05 12:07

    Have you tried something like android:layout_height="30dp" instead of fill_parent for either of those elements in loginrowspinner.xml?

    0 讨论(0)
  • 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

    0 讨论(0)
  • 2021-02-05 12:11

    add this in your adapter : convertView.setMinimumHeight(60); which works for me.

    0 讨论(0)
提交回复
热议问题