DropDown Spinner Alignment

2019-09-18 16:16发布

I develop an Adroid application. So i want to customize programmatically the behavior of DropDown Spinner. I overwrite the getDropDownView method but i cannot find anything to change the dimension of DropDown and also the alignment of it. I only change the color of each line in DropDown like this

            View view = this.getView(position, convertView, parent);
        if (position % 2 == 0) {
            view.setBackgroundColor(Color.YELLOW);
        } else {
            view.setBackgroundColor(Color.GRAY);
        }

Can someone help me? Thanks

2条回答
淡お忘
2楼-- · 2019-09-18 16:18

I wait for someone to help me. Not happened. So i found a workaround. I use a TextView and on click a ListView is displayed. So if someone find a better approach, please let me know

查看更多
戒情不戒烟
3楼-- · 2019-09-18 16:45

The alignment/horizontal offset of a spinner dropdown (which is a PopUp) is controlled by the value of the left padding of the spinner itself.

Therefore setting the left padding of a spinner to 0dp or between 0dp - 2dp should correct the left alignment, then setting a proper dropdown width with the .setDropDownWidth method of the spinner should correct the the right alignment.

To get a proper dropdown width, get the layout parameters of the spinner, and pass its width property to the .setDropDownWidth method of the spinner, you might have to make some little adjustment on this value to get the required alignment.

查看更多
登录 后发表回答