how to change the dropdown height in spinner

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

    You can try using dps.

    @Override   
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
    
        LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    
        TextView textview = (TextView)inflater.inflate(android.R.layout.simple_spinner_item, null);
    
        textview.setText(alOpcion.get(position).getOpcionName());
    
        DisplayMetrics metrics = parent.getResources().getDisplayMetrics();
        float dp = 40f;
        float fpixels = metrics.density * dp;
        int pixels = (int) (fpixels + 0.5f);
    
        textview.setHeight(pixels);
    
        return textview;
    }
    

提交回复
热议问题