0

내 앱의 경우 전체 레이아웃에서 자체 ScrollView를 구현하는 library을 사용하고 있습니다. Why You No Work?! http://oi43.tinypic.com/vgtlvs.jpg 내가 내을 만들어 결국사용자 정의보기에서 GridView를 재활용 하시겠습니까?

(상단의 슬라이더를 무시) :

내 문제는 내가 조각에서의 GridView이 필요하지만, 그렇게하는 대부분의 그것의은과 같이 잘려되도록한다는 것이다 행 수에 따라 확장되지만보기 재활용을 사용하지 않는 자체 GridView. 우리가 많은 이미지를 사용하기 때문에 우리는 10을 넘으면 모든 종류의 OutOfMemoryExceptions을 얻게됩니다. 우리는 또한 스크롤하는 동안 보게되는 애니메이션을 사용할 수 없습니다.

public class PkGridView extends GridView implements OnTouchListener, OnScrollListener 
{ 

private int listViewTouchAction; 
private static final int MAXIMUM_LIST_ITEMS_VIEWABLE = 50; 

public PkGridView(Context context, AttributeSet attrs) 
{ 
    super(context, attrs); 
    listViewTouchAction = -1; 
    setOnScrollListener(this); 
    setOnTouchListener(this); 
} 

@Override 
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) 
{ 
    if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) 
    { 
     if (listViewTouchAction == MotionEvent.ACTION_MOVE) 
     { 
      scrollBy(0, -1); 
     } 
    } 
} 

@Override 
public void onScrollStateChanged(AbsListView view, int scrollState) 
{ 
} 

@Override 
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) 
{ 
    super.onMeasure(widthMeasureSpec, heightMeasureSpec); 

    int newHeight = 0; 
    final int heightMode = MeasureSpec.getMode(heightMeasureSpec); 
    int heightSize = MeasureSpec.getSize(heightMeasureSpec); 
    if (heightMode != MeasureSpec.EXACTLY) 
    { 
     ListAdapter listAdapter = getAdapter(); 
     if (listAdapter != null && !listAdapter.isEmpty()) 
     { 
      int listPosition = 0; 
      for (listPosition = 0; listPosition < listAdapter.getCount() && listPosition < MAXIMUM_LIST_ITEMS_VIEWABLE; listPosition++) 
      { 
       View listItem = listAdapter.getView(listPosition, null, this); 
       // now it will not throw a NPE if listItem is a ViewGroup instance 
       if (listItem instanceof ViewGroup) 
       { 
        listItem.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); 
       } 
       listItem.measure(widthMeasureSpec, heightMeasureSpec); 
       newHeight += listItem.getMeasuredHeight(); 
      } 
      //newHeight += 5 * listPosition; 
     } 
     if ((heightMode == MeasureSpec.AT_MOST) && (newHeight > heightSize)) 
     { 
      if (newHeight > heightSize) 
      { 
       newHeight = heightSize; 
      } 
     } 
    } 
    else 
    { 
     newHeight = getMeasuredHeight(); 
    } 
    setMeasuredDimension(getMeasuredWidth(), newHeight); 
} 

@Override 
public boolean onTouch(View v, MotionEvent event) 
{ 
    if (getAdapter() != null && getAdapter().getCount() > MAXIMUM_LIST_ITEMS_VIEWABLE) 
    { 
     if (listViewTouchAction == MotionEvent.ACTION_MOVE) 
     { 
      scrollBy(0, 1); 
     } 
    } 
    return false; 
} 
} 

가 내 항목을 가질 수있는 방법이 있나요 재활용 다시 아직 확장하지 않고 전체의 GridView를 볼 수있는 반면 다음은

내 정의의 GridView에 대한 코드?

답변

1

자신 만의 어댑터 구현을 사용해야합니다. 모든 비동기 이미지 로딩 및보기 재활용 ListView를 /의 GridView에 표시 비트 맵에 대한 완전한 솔루션을 제공하지 안드로이드 개발자에 좋은 훈련이있다 :의 getView에서 사용자 정의 어댑터에서

http://developer.android.com/training/displaying-bitmaps/process-bitmap.html

은 (...) 그에 따라 ViewHolder 패턴을 사용하고 loadBitmap (...)을 호출하면 완료됩니다. 난 이미 내 자신의 어댑터와 피카소 라이브러리 I을 사용하고, 사실

http://developer.android.com/training/custom-views/index.html

+0

: 사용자 정의보기를 들어

http://www.vogella.com/articles/AndroidListView/article.html#adapterown_custom

어쩌면이 하나가 흥미로운 너무 : 사용자 정의 어댑터를 만들기위한이 자습서를 참조하십시오 이미지로드에 사용하는 것이 효율적일 수 있습니다. 아, 그리고 이미 ViewHolder 패턴을 사용하고 있습니다. 여기에서 문제는 내가 사용하고있는 FadingActionBar 라이브러리가 GridView/ListView에 헤더가 있어야한다는 것입니다. 나는 현재이 문제를 해결하기 위해이 [HeaderGridView] (https://github.com/maurycyw/HeaderGridView) 라이브러리를 시험하고 있지만 여전히 운이 없다. – Pkmmte

관련 문제