나는 알아 냈다. 조금 복잡하지만 대부분 작동하는 것 같습니다 :
public int usedHeightForAndAfterDesiredRow() {
int totalHeight = 0;
for (int index = 0; index < rowHeights.size(); index++) {
int height = rowHeights.get(rowHeights.keyAt(index));
totalHeight += height;
}
return totalHeight;
}
@Override
public View getView(int position, View convertView, final ViewGroup parent) {
View view = super.getView(position, convertView, parent);
if (measuringLayout.getLayoutParams() == null) {
measuringLayout.setLayoutParams(new AbsListView.LayoutParams(parent.getWidth(), parent.getHeight()));
}
// measure the row ahead of time so that we know how much space will need to be added at the end
if (position >= mainRowPosition && position < getCount()-1 && rowHeights.indexOfKey(position) < 0) {
measuringLayout.addView(view, new FrameLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
measuringLayout.measure(MeasureSpec.makeMeasureSpec(parent.getWidth(), MeasureSpec.EXACTLY), MeasureSpec.UNSPECIFIED);
rowHeights.put(position, view.getMeasuredHeight());
measuringLayout.removeAllViews();
view.setLayoutParams(new AbsListView.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
if (position == getCount()-1 && view.getLayoutParams().height == 0) {
// we know how much height the prior rows take, so calculate the last row with that.
int height = usedHeightForAndAfterDesiredRow();
height = Math.max(0, parent.getHeight() - height);
view.getLayoutParams().height = height;
}
return view;
}
이것은 내 어댑터에 들어 있습니다. 그것은 병합 어댑터의 하위 클래스이지만 코드에 넣고 행을 생성하는 대신 수퍼 호출을 대신 사용할 수 있습니다.
getView()의 첫 번째 if 문은 측정만을위한 프레임 레이아웃 멤버 var의 레이아웃 매개 변수를 설정하며 상위 뷰는 없습니다.
두 번째 if 문은 맨 위로 스크롤하는 데 신경 쓰는 행의 위치를 포함하여 행의 모든 행 높이를 계산합니다. rowHeights는 SparseIntArray입니다.
마지막 if 문은 레이아웃 매개 변수가있는보기가 추가로 하나만있는 것으로 가정합니다.보기의 맨 아래에 이미 투명하고 확장되도록 의도 된 레이아웃 매개 변수가 이미 설정되어 있습니다. usedHeightForAndAfterDesiredRow 호출은 상위 뷰의 높이에서 빼는 모든 미리 계산 된 높이를 더합니다 (최소 높이가 0이되므로 음수 높이를 얻지 못합니다). 이렇게하면 다른 항목의 높이에 따라 임의로 펼쳐지는 아래쪽에보기가 작성되므로 목록의 위치에 관계없이 특정 행이 항상 목록의 맨 위로 스크롤 할 수 있습니다.
목록의 마지막 요소를 스크롤하여 화면 아래에 빈 공간이 있는지를 의미합니까? – Gustek
그래, 그게 내가해야 할 일이다. – Kevlar
꽤 해킹 된 것이지만 ... 빈 끝에 [footer] (http://developer.android.com/reference/android/widget/ListView.html#addFooterView%28android.view.View.29)를 추가하십시오. 화면 크기의 목록? –