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
//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;
}
};
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;
}
Have you tried something like android:layout_height="30dp"
instead of fill_parent
for either of those elements in loginrowspinner.xml?
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
add this in your adapter : convertView.setMinimumHeight(60); which works for me.