How can I make the spinner width same as largest available item width

前端 未结 7 1697
天涯浪人
天涯浪人 2021-01-31 07:44

I realize even I use wrap_content for my spinner (I avoid using match_parent as I do not want the spinner overly long), and using match_parent

7条回答
  •  渐次进展
    2021-01-31 07:53

    You can try spinnerMode="dialog" but it is just a workaround, not the right answer. Because it will display a new window with a dialog.

    So here is the way do to it. It will automatically fit the content.

    It strongly depends how you set up your custom layout. May i suggest you to write your own xml file myspinner_custom_dropdown.xml. Recommanded way is now ConstraintLayout from androidX.

    
    
    
        
    
        
    
    
    

    Important : you have yo use your custom layout with your adapter

    dataAdapter.setDropDownViewResource(R.layout.myspinner_custom_dropdown);
    

    That's all, you do not need some kinds of hardcored attributes in your spinner declaration.

     
    

提交回复
热议问题