2012-12-20 2 views
2

프레임 레이아웃에 사용자 정의 gridView와 버튼이 있습니다. 코드는 다음과 같습니다안드로이드에서 gridView의 스크롤 리스너에서 버튼을 보이게하거나 사라지게하는 방법

<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    <GridView 
     android:id="@+id/gridview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_alignParentBottom="true" 
     android:layout_below="@+id/Rel_Spinner" 
     android:layout_centerHorizontal="true" 
     android:gravity="center" 
     android:numColumns="auto_fit" 
     android:stretchMode="columnWidth" > 
    </GridView> 


    <FrameLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:layout_alignParentLeft="true" > 


     <Button 
      android:id="@+id/btnLoadMore" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:text="Load More" /> 

    </FrameLayout> 

</RelativeLayout> 

이미지와 텍스트를 어댑터에서로드합니다. 그림과 같이

enter image description here

지금 내가 원하는

은의 GridView 스크롤의 최종 위치가 다시 사라집니다 다른 현명한에 도달 할 때 버튼을 표시해야한다는 것입니다. 그림과 같이

enter image description here

답변

0

당신은의 GridView에 대한 setOnScrollListener를 사용하여이 작업을 수행 할 수 있습니다 : 대한 답변을

gridview.setOnScrollListener(new OnScrollListener() { 

    @Override 
    public void onScroll(AbsListView view, int firstVisibleItem, 
       int visibleItemCount, int totalItemCount) { 

     } 

    @Override 
    public void onScrollStateChanged(AbsListView view, int scrollState) { 
      // TODO Auto-generated method stub 
     switch(scrollState) { 
     case 2: // SCROLL_STATE_FLING 
     //hide button here 
     break; 

     case 1: // SCROLL_STATE_TOUCH_SCROLL 
     //hide button here 
     break; 

     case 0: // SCROLL_STATE_IDLE 
     //show button here 
     break; 

      default: 
      //show button here 
     break; 
      } 
     } 
    }); 
+0

감사합니다. 그것으로 나는 필요한대로 일했다. 그러나 전략은 여기에서 바뀌었다. 보스는 Extra Button (Load More)을 사용하지 않고 스크롤 목록의 gridView에 더 많은 이미지를로드해야한다고 말했습니다. 처음에는 내 gridView 12 이미지와 12 textViews로 가득 차 있습니다. 그럼 GridView의 마지막 항목, 즉 12 번째 항목에 도달하면 12 개의 이미지와 텍스트를 어떻게 추가로로드 할 수 있습니까? 이 점에 대해 도움을주십시오. –

+0

@ QadirHussain : 현재 문제 해결에 도움이 될 수있는 [this] (http://stackoverflow.com/questions/12170466/android-using-gridview-with-onscrolllistener)를 참조하십시오. –

관련 문제