Tại sao không chỉ cần kiểm tra vị trí của mặt hàng tương đối so với kích thước danh sách của bạn:
Padding:
public View getView(int position, View convertView, ViewGroup parent)
{
//recycle views and whatever else you normally would do goes here..
//...
//...
if (position == 0){
convertView.setPadding(0, 10, 0, 0); //padding on top for top item
}
else if (position == getCount() - 1){
convertView.setPadding(0, 0, 0, 10); //padding on bottom for bottom item
}
else{
convertView.setPadding(0, 0, 0, 0); //no padding
}
}
Đối với lợi nhuận sử dụng
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
lp.setMargins(left, top, right, bottom);
convertView.setLayoutParams(lp);
Ex :
public View getView(int position, View convertView, ViewGroup parent)
{
//recycle views and whatever else you normally would do goes here..
//...
//...
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
if (position == 0){
lp.setMargins(0, 10, 0, 0); //margin on top for top item
}
else if (position == getCount() - 1){
lp.setMargins(0, 10, 0, 10); //margin on bottom for bottom item
}
else{
lp.setMargins(0, 0, 0, 0); //no margin
}
convertView.setLayoutParams(lp);
}
điều này được cung cấp bạn đã triển khai phương thức getCount() phù hợp với bộ điều hợp của bạn.
Nasty gợi ý, nhưng làm thế nào về một đỉnh/đáy đệm cho xem mục đầu tiên/cuối cùng? Bạn sẽ phải kiểm tra và đặt nó trên tất cả các khung nhìn trong 'getView' ... – Knickedi