【问题标题】:How Do I Set My Spinner Layout Appropriately?如何正确设置微调器布局?
【发布时间】:2014-04-04 05:04:07
【问题描述】:

请参阅下面的屏幕截图。对于前两个字段,我只使用了 ArrayAdapaters(int 和 String)。第三,我创建了一个自定义适配器(和自定义 Spinner 对象),以便显示提示。除了格式看起来很糟糕之外,一切都运行良好。下拉项更小,并且不像其他项那样被填充。 “Credit”下方的行也高于其他微调器。在我选择一个值后,这条线会调整到它应该在的位置。

我该去哪里修复格式?高度和宽度设置与 XML 中的其他微调器相匹配。我对此比较陌生。

【问题讨论】:

    标签: android android-layout layout spinner


    【解决方案1】:

    在您的自定义微调器适配器中,您应该有:

    public View getView(int position, View convertView, ViewGroup parent) {
    
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(yourSelectedItemLayout, parent,false);
        TextView make = (TextView) row.findViewById(R.id.Make);
        v.setText(data.get(position));
        return row;
    }
    
    
    public View getDropDownView(int position, View convertView, ViewGroup parent) {
    
        LayoutInflater inflater = getLayoutInflater();
        View row = inflater.inflate(yourDropDownlayoutOut, parent,false);
        TextView make = (TextView) row.findViewById(R.id.Make);
        v.setText(data.get(position));
        return row;
    }
    

    yourSelectedItemLayout 和 yourDropDownlayoutOut 将是您创建的布局,您可以在其中设置自己的格式。

    【讨论】:

      猜你喜欢
      • 2016-08-07
      • 2018-12-22
      • 2012-01-25
      • 1970-01-01
      • 2017-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多