Android ScrollView 와 ListView 가 함께 사용 하 는 문제 모음

11662 단어 scrollview
1. ScrollView 내장 ListView ,터치 사건 의 캡 처 문제.
레 퍼 런 스 http://www.cnblogs.com/lqminn/archive/2013/03/02/2940194.htmlhttp://blog.csdn.net/chaihuasong/article/details/17499799
_scrollView.requestDisallowInterceptTouchEvent(true);

이 말 은 스크롤 뷰 에 굴 러 가 는 사건 을 저 에 게 맡 기 라 는 뜻 입 니 다.다 쓴 다음 에 꼭 돌려 주세요.
_scrollView.requestDisallowInterceptTouchEvent(false);

설정 하지 않 으 면 스크롤 뷰 를 굴 릴 수 없습니다.
 
2. ScrollView 가 굴 러 갈 때 ListView 의 첫 번 째 항목 이 표 시 된 상태 입 니까?
레 퍼 런 스 http://stackoverflow.com/questions/4628800/android-how-to-check-if-a-view-inside-of-scrollview-is-visible
boolean checkNeedRefresh() {
        Rect scrollBounds = new Rect();
        View firstChild = listView.getChildAt(0);
        _scrollView.getHitRect(scrollBounds);
        if (firstChild.getLocalVisibleRect(scrollBounds)) {
            // Any portion of the firstChild, even a single pixel, is within the
            // visible window
            return true;
        } else {
            // NONE of the firstChild is within the visible window
            return false;
        }
    }

 
3. listView 전체 표시 불가
레 퍼 런 스http://blog.csdn.net/hahashui123/article/details/39177057http://blog.csdn.net/solomonxiang/article/details/26507145
public static void setListViewHeight(ListView listView) {
        try {
            int totalHeight = 0;
            ListAdapter adapter = listView.getAdapter();
            for (int i = 0, len = adapter.getCount(); i < len; i++) { // listAdapter.getCount()
                View listItem = adapter.getView(i, null, listView);
                listItem.setLayoutParams(new LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

                listItem.measure(0, 0); 
                totalHeight += listItem.getMeasuredHeight(); 
            }

            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = totalHeight
                    + (listView.getDividerHeight() * (listView.getCount() - 1));
            listView.setLayoutParams(params);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

GridView
public static void setGridViewHeight(GridView gridView, int numColumns) {
        try {
            ListAdapter adapter = gridView.getAdapter();
            int row = 3;
            View listItem = adapter.getView(0, null, gridView);
            if (listItem == null)
                return;
            listItem.setLayoutParams(new LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            listItem.measure(0, 0); 
            int totalHeight = listItem.getMeasuredHeight() * row
                    + (gridView.getVerticalSpacing() * (row - 1));
            ViewGroup.LayoutParams params = gridView.getLayoutParams();
            params.height = totalHeight;
            gridView.setLayoutParams(params);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

 ListView 에 BottomView 가 있 으 면
public static void setListViewHeight(ListView listView) {
        try {
            int totalHeight = 0;
            int bottomHeight = 0;
            ListAdapter dataAdapter = null;
            int totalItems = 0;
            ListAdapter adapter = listView.getAdapter();
            if (adapter instanceof HeaderViewListAdapter) {
                HeaderViewListAdapter headerViewListAdapter = ((HeaderViewListAdapter) adapter);
                dataAdapter = headerViewListAdapter.getWrappedAdapter();
                totalItems = dataAdapter.getCount();
                int allItems = headerViewListAdapter.getCount();
                View bottomItem = headerViewListAdapter.getView(allItems - 1,
                        null, listView);
                bottomItem.measure(0, 0);
                bottomHeight = bottomItem.getMeasuredHeight();

            } else {
                dataAdapter = adapter;
            }

            for (int i = 0, len = totalItems; i < len; i++) {
                View listItem = dataAdapter.getView(i, null, listView);
                listItem.setLayoutParams(new LayoutParams(
                        LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

                listItem.measure(0, 0);
                totalHeight += listItem.getMeasuredHeight();
            }

            int listviewCount = listView.getCount();
            int height = totalHeight
                    + (listView.getDividerHeight() * listviewCount + 1)
                    + bottomHeight;

            ViewGroup.LayoutParams params = listView.getLayoutParams();
            params.height = height;
            listView.setLayoutParams(params);
            listView.requestLayout();
             
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }

 
4. 기타, 사용자 정의 컨트롤 구현 ListView
http://www.cnblogs.com/lesliefang/p/3587154.html 
 5. 로 딩 이 완 료 될 때마다 listview 는 화면 맨 위로 굴 러 가 는 것 을 발견 합 니 다. 실제로 listview 위 에 덮 인 것 이 있 습 니 다. 해결 방법 은 다음 과 같 습 니 다.
  <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:descendantFocusability="blocksDescendants"
            android:orientation="vertical" >

가장 중요 한 한 마디 는 srcollview 의 콘 텐 츠 컨트롤 을 찾 습 니 다. 보통 LinearLayout 이 고 속성 을 추가 합 니 다. android: descendant Focusability = "blocks Descendants" 면 됩 니 다.

좋은 웹페이지 즐겨찾기