2017-01-06 1 views
0

를 아래로 스크롤이 표시되지 않습니다 매우 빠르게 내 옛날보기로 스크롤합니다. 사용자가이 스크롤을 어떻게 볼 수 없습니까? 여기에 내 문제를 설명하기 비디오입니다 : https://drive.google.com/open?id=0B7LMfg4tJlisVVlXajVuVlIyd3cnotifydatasetchanged는() 나는 이런 식으로 뭔가를 시도 효과를

내 어댑터

공용 클래스 CardsViewAdapter이 RecyclerView.Adapter를 확장 { 개인 게임 [] mDataset; // 개인 부울입니다. isPopupVisible = false; int rotationAngle = 0;

// Provide a reference to the views for each data item 
// Complex data items may need more than one view per item, and 
// you provide access to all the views for a data item in a view holder 
public static class ViewHolder extends RecyclerView.ViewHolder { 
    // each data item is just a string in this case 
    public TextView mTextView; 
    public ImageView imageView; 
    public LinearLayout test2; 
    public TextView test3; 
    boolean isPopupVisible; 

    public ViewHolder(View v) { 
     super(v); 
     mTextView = (TextView) v.findViewById(R.id.text_cards); 
     imageView = (ImageView) v.findViewById(R.id.item_description_game_more); 
     test2 = (LinearLayout) v.findViewById(R.id.popup_layout); 
     test3 = (TextView) v.findViewById(R.id.test_view); 
     isPopupVisible = false; 

    } 
} 

// Provide a suitable constructor (depends on the kind of dataset) 
public CardsViewAdapter(Game[] myDataset) { 
    mDataset = myDataset; 
} 

// Create new views (invoked by the layout manager) 
@Override 
public CardsViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, 
               int viewType) { 
    // create a new view 
    View v = LayoutInflater.from(parent.getContext()) 
      .inflate(R.layout.cards_resume_game, parent, false); 
    // set the view's size, margins, paddings and layout parameters 
    //... 

    ViewHolder vh = new ViewHolder(v); 
    return vh; 
} 

// Replace the contents of a view (invoked by the layout manager) 
@Override 
public void onBindViewHolder(final ViewHolder holder, int position) { 
    // - get element from your dataset at this position 
    // - replace the contents of the view with that element 
    //TODO : complete 
    final int pos = position; 
    holder.mTextView.setText(String.valueOf(mDataset[position].getId_game())); 
    holder.test3.setText("Position : "+pos); 
    // Set the expanded or collapsed mode here 
    if(mDataset[position].expanded) 
     expandView(holder.test2,holder.imageView); 
    else 
     collapseView(holder.test2,holder.imageView); 


    // Now set the onClickListener like this 
    holder.imageView.setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View v) { 


      // Animate the imageView here 
      animateImageView(holder.imageView); 

      // Toggle the expanded attribute value 
      if(mDataset[pos].expanded) mDataset[pos].expanded = false; 
      else mDataset[pos].expanded = true; 

      // Now call notifyDataSetChanged to make the change to effect 
      refreshList(); 
     } 
    }); 



} 

// Extra functions inside your adapter class to improve readability 
private void collapseView(View v,ImageView imageView) { 
    CardsAnimationHelper.collapse(v); 
} 


private void expandView(View v,ImageView imageView) { 
    CardsAnimationHelper.expand(v); 
} 

private void animateImageView(ImageView imageView) { 
    ObjectAnimator anim = ObjectAnimator.ofFloat(imageView, "rotation",rotationAngle, rotationAngle + 180); 
    anim.setDuration(animationDuration); 
    anim.start(); 
    rotationAngle += 180; 
    rotationAngle = rotationAngle % 360; 
} 

long animationDuration = 500; 

private void refreshList() { 
    final Handler handler = new Handler(); 
    handler.postDelayed(new Runnable() { 
     @Override 
     public void run() { 
      notifyDataSetChanged(); 
     } 
    }, animationDuration); 
} 

// Return the size of your dataset (invoked by the layout manager) 
@Override 
public int getItemCount() { 
    return mDataset.length; 
} 
+0

는, notifyDataSetChanged() 메소드를 사용하여 그것을 시도 포기하지 마십시오 holder.imageView.setOnClickListener를 (새 View.OnClickListener() { @Override 공공 무효 온 클릭 (보기 V) { //은 토글 다른 mDataset 사실 [POS] .expanded =; (mDataset [위치] .expanded) 경우 expandView (holder.test2 확장 속성 값 는 경우 (mDataset [POS]가 .expanded) mDataset [POS는 = 거짓을 .expanded , holder.imageView) else collapseView (holder.test2, holder.imageView); } }}); –

+0

답장을하고 무언가를 확인한 후에 받아 들일 수 있습니까? – filol

+0

도움이된다면 먼저 시도해 보시기 바랍니다. –

답변

0

RecyclerView의 notifyItemChanged(int position) 방법을 사용하면 목록이 완전히 새로 고쳐지지 않습니다.

시각적으로 더 매력적이기 때문에 레이아웃 파일에 android:animateLayoutChanges="true"을 사용할 수도 있습니다.이 레이아웃은 자동으로 layoutchanges (https://developer.android.com/training/animation/layout.html)에 적용됩니다.

+0

고마워, 그게 내가 필요한거야. – filol

0

notifydatasetchanged() 그냥 업데이트됩니다. 스크롤하려면 recyclerview.smoothScrollToPosition(int position)을 사용하십시오.

0

두 가지 방법으로 스크롤 할 수 있습니다.

  1. smoothScrollToPosition (INT 위치)

  • setSelection (INT 위치) 귀하의 요구 사항에 따라 게시하거나 postDelayed에서이 작업을 수행 [당신은 smoothscroll를 달성하려면].

  • 관련 문제