ListView 的第一行高度

1st Row of ListView Height

我正在尝试使 listView 的第一行的高度高于其余行。我可以为第 1 行应用不同的布局,但我不能使高度不同。我正在使用自定义适配器...这是我的 getView,它选择了适当的行布局:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    int theType = getItemViewType(position);

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) parent.getContext()
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

        if (theType == 0) {
            convertView = inflater.inflate(R.layout.location_list_row_one, null);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
            imagView.setBackground(R.drawable.image);
            TextView name = (TextView) convertView.findViewById(R.id.name);
            name.setText("Name");

        } else if (theType == 1) {
            convertView = inflater.inflate(R.layout.location_list_row_two, null);
            ImageView imageView = (ImageView) convertView.findViewById(R.id.image);
            imagView.setBackground(R.drawable.image);
            TextView name = (TextView) convertView.findViewById(R.id.name);
            name.setText("Name");
        }
    }
    return convertView;
}

我的行布局包含在相对布局中,因此我需要使第一行的 RL 高度更高。有什么想法吗?

你可以试试 padding:

convertView.setPadding(left, right, top, bottom);

您可以使用不同的布局并将标题视图添加到列表视图。