2012-04-15 3 views
6

내 자신의 overscroll 기능을 구현할 수 있도록 내 listviews에서 overscroll을 완전히 비활성화해야합니다.삼성 갤럭시 탭 2.3.3에서 목록보기 overscroll 사용 안드로이드

overscroll 모드를 OVERSCROLL_NEVER로 설정하여 핵심 목록 뷰 클래스를 살펴볼 때 충분히 단순 해 보입니다. 내 삼성 갤럭시 s2 에서이 잘 작동합니다. 하지만 작동하지 않습니다 Galaxy Tab 2.3.3.

누가 나를 도울 수있는 삼성 ListView 사용자 정의에 많은 경험이 있었나요?

답변

2

목록 뷰의 높이를 고정 값으로 설정해야합니다. 콘텐츠를 동적으로 어댑터를 재설정 한 후 실제 listsize을 측정하는 좋은 기능이있는 경우 :

public static void setListViewHeightBasedOnChildren(ListView listView) { 
    ListAdapter listAdapter = listView.getAdapter(); 
    if (listAdapter == null) { 
     // pre-condition 
     return; 
    } 

    int totalHeight = 0; 
    int desiredWidth = MeasureSpec.makeMeasureSpec(listView.getWidth(), MeasureSpec.AT_MOST); 
    for (int i = 0; i < listAdapter.getCount(); i++) { 
     View listItem = listAdapter.getView(i, null, listView); 
     listItem.measure(desiredWidth, MeasureSpec.UNSPECIFIED); 
     totalHeight += listItem.getMeasuredHeight(); 
    } 

    ViewGroup.LayoutParams params = listView.getLayoutParams(); 
    params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1)); 
    listView.setLayoutParams(params); 
    listView.requestLayout(); 
} 

당신이 당신의 어댑터를 설정 한 후에 있었던 파라미터와 같은 목록보기이 정적 메소드를 호출해야합니다. 이제 scrollview를 추가 할 수 있습니다 (목록보기 및 기타보기 내부에 있음). 2.3.3에서의이 동작은 이전의 작은 버그입니다 ... 내가 설명한 방법을 제외하고는 scrollview 안에 listview를 포함시키는 쉬운 방법이 없습니다. 그런 이유로 그들은 OVERSCROLL_NEVER 모드를 도입했습니다 :

코드는 DougW에서입니다!

3
그것은 (안드로이드 2.2) 삼성 갤럭시 탭에 나를 위해 일한

:

try { 

    // list you want to disable overscroll 
    // replace 'R.id.services' with your list id 
    ListView listView = ((ListView)findViewById(R.id.services)); 

    // find the method 
    Method setEnableExcessScroll = 
      listView.getClass().getMethod("setEnableExcessScroll", Boolean.TYPE); 

    // call the method with parameter set to false 
    setEnableExcessScroll.invoke(listView, Boolean.valueOf(false)); 

} 
catch (SecurityException e) {} 
catch (NoSuchMethodException e) {} 
catch (IllegalArgumentException e) {} 
catch (IllegalAccessException e) {} 
catch (InvocationTargetException e) {} 
+0

브릴리언트! 이것은 정말 저에게 많은 번거 로움을 덜어주었습니다. 어떤 메소드 이름을 찾아야할지 어떻게 알았습니까? S2 API 공개입니까? – npace

관련 문제