Android Spinner - How to position dropdown arrow as close to text as possible when options have different length?

后端 未结 2 1720
借酒劲吻你
借酒劲吻你 2021-01-11 15:04

The options in my spinner has different length and currently the dropdown arrow is positioned far to the right based on the longest option, as shown in the screenshot below.

2条回答
  •  旧巷少年郎
    2021-01-11 15:30

    Translating @尹小雨 answer to java

        ArrayAdapter adapter = new ArrayAdapter(this,R.layout.spinner_item_main,objects); // creates new ArrayAdapter with custom textviews for all elements including the first one (which is what we want)
        adapter.setDropDownViewResource(R.layout.spinner_dropdown_view_main); // Modifies all the elements when you click on the dropdown
        spinner.setAdapter(adapter); // sets the adapter to the spinner
    

提交回复
热议问题