ScrollView에 포함된 ListView는 하나의 해결 방법만 표시합니다.
1987 단어 scrollviewlistview
ScrollView에 ListView를 추가하면 listview 컨트롤이 완전하지 않습니다. 보통 하나만 표시됩니다. 도대체 어떤 이유입니까?
두 컨트롤의 스크롤 이벤트 충돌로 인해따라서listview의 item 수량을 통해listview의 디스플레이 높이를 계산하여 완전하게 보여야 한다. 다음은 참고할 수 있는 방법을 제공한다.
해결 방법은 다음과 같습니다.
lv = (ListView) findViewById(R.id.lv);
adapter = new MyAdapter();
lv.setAdapter(adapter); setListViewHeightBasedOnChildren(lv);
---------------------------------------------------
public void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++)
{ View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
params.height += 5;
listView.setLayoutParams(params); }
현재 단계에서 가장 좋은 방법은 사용자 정의 ListView, onMeasure () 방법을 다시 불러오고 모든 디스플레이를 설정하는 것입니다.
import android.widget.ListView;
/** * * @Description: scrollview listview
* * @File: ScrollViewWithListView.java
* * * @Version */
public class ScrollViewWithListView extends ListView {
public ScrollViewWithListView(android.content.Context context, android.util.AttributeSet attrs) { super(context, attrs); }
/**
* Integer.MAX_VALUE >> 2, , */
public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); super.onMeasure(widthMeasureSpec, expandSpec);
}
}
위의 내용은 여러분에게 소개된 ScrollView에 ListView를 삽입하여 하나만 표시하는 해결 방법입니다. 여러분에게 도움이 되기를 바랍니다!
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
수평listview를 실현하고 수평listview가scrollview에서 발생하는 미끄럼 충돌을 해결합니다수평 ListView를 구현하고 ScrollView에서 수평 ListView의 슬라이딩 충돌 해결 먼저 위 그림: 해결된 문제는 다음과 같습니다. 1) 수평 슬라이딩을 구현하는 ListView입니다.AdapterVi...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.