當前位置: 首頁>>代碼示例>>Java>>正文


Java ViewHolder類代碼示例

本文整理匯總了Java中android.support.v7.widget.RecyclerView.ViewHolder的典型用法代碼示例。如果您正苦於以下問題:Java ViewHolder類的具體用法?Java ViewHolder怎麽用?Java ViewHolder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ViewHolder類屬於android.support.v7.widget.RecyclerView包,在下文中一共展示了ViewHolder類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: findSwapTargets

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private List<ViewHolder> findSwapTargets(ViewHolder viewHolder) {
    if (this.mSwapTargets == null) {
        this.mSwapTargets = new ArrayList();
        this.mDistances = new ArrayList();
    } else {
        this.mSwapTargets.clear();
        this.mDistances.clear();
    }
    int margin = this.mCallback.getBoundingBoxMargin();
    int left = Math.round(this.mSelectedStartX + this.mDx) - margin;
    int top = Math.round(this.mSelectedStartY + this.mDy) - margin;
    int right = (viewHolder.itemView.getWidth() + left) + (margin * 2);
    int bottom = (viewHolder.itemView.getHeight() + top) + (margin * 2);
    int centerX = (left + right) / 2;
    int centerY = (top + bottom) / 2;
    LayoutManager lm = this.mRecyclerView.getLayoutManager();
    int childCount = lm.getChildCount();
    for (int i = 0; i < childCount; i++) {
        View other = lm.getChildAt(i);
        if (other != viewHolder.itemView && other.getBottom() >= top && other.getTop() <= bottom && other.getRight() >= left && other.getLeft() <= right) {
            ViewHolder otherVh = this.mRecyclerView.getChildViewHolder(other);
            if (this.mCallback.canDropOver(this.mRecyclerView, this.mSelected, otherVh)) {
                int dx = Math.abs(centerX - ((other.getLeft() + other.getRight()) / 2));
                int dy = Math.abs(centerY - ((other.getTop() + other.getBottom()) / 2));
                int dist = (dx * dx) + (dy * dy);
                int pos = 0;
                int cnt = this.mSwapTargets.size();
                int j = 0;
                while (j < cnt && dist > ((Integer) this.mDistances.get(j)).intValue()) {
                    pos++;
                    j++;
                }
                this.mSwapTargets.add(pos, otherVh);
                this.mDistances.add(pos, Integer.valueOf(dist));
            }
        }
    }
    return this.mSwapTargets;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:40,代碼來源:ItemTouchHelper.java

示例2: endChangeAnimationIfNecessary

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder != item) {
        return false;
    } else {
        changeInfo.oldHolder = null;
        oldItem = true;
    }
    ViewCompat.setAlpha(item.itemView, 1.0f);
    ViewCompat.setTranslationX(item.itemView, 0.0f);
    ViewCompat.setTranslationY(item.itemView, 0.0f);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:17,代碼來源:DefaultItemAnimator.java

示例3: onCreateViewHolder

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View view;
    if (viewType == TYPE_ITEM) {
        if (mContext == null) {
            mContext = parent.getContext();
        }
        view = LayoutInflater.from(mContext).inflate(R.layout.content_search_needs, parent, false);
        if (orderDao == null) orderDao = new OrderDao(mContext);
        final ItemViewHolder holder = new ItemViewHolder(view);
        return holder;
    }
    else if (viewType == TYPE_FOOTER) {
        view = LayoutInflater.from(mContext).inflate(R.layout.item_foot, parent,
                false);
        Log.e("!!!!!","111111111111");
        return new FootViewHolder(view);
    }
    return null;
}
 
開發者ID:Luodian,項目名稱:Shared-Route,代碼行數:21,代碼來源:PullRecyclerViewAdapter.java

示例4: animateChange

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@Override
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY,
                             int toX, int toY) {
    final float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    final float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    final float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    endAnimation(oldHolder);
    int deltaX = (int) (toX - fromX - prevTranslationX);
    int deltaY = (int) (toY - fromY - prevTranslationY);
    // recover prev translation state after ending animation
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null && newHolder.itemView != null) {
        // carry over translation values
        endAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, -deltaX);
        ViewCompat.setTranslationY(newHolder.itemView, -deltaY);
        ViewCompat.setAlpha(newHolder.itemView, 0);
    }
    mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
開發者ID:SalmanTKhan,項目名稱:MyAnimeViewer,代碼行數:24,代碼來源:BaseItemAnimator.java

示例5: popFromLayoutStep

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private ItemHolderInfo popFromLayoutStep(ViewHolder vh, int flag) {
    ItemHolderInfo itemHolderInfo = null;
    int index = this.mLayoutHolderMap.indexOfKey(vh);
    if (index >= 0) {
        InfoRecord record = (InfoRecord) this.mLayoutHolderMap.valueAt(index);
        if (!(record == null || (record.flags & flag) == 0)) {
            record.flags &= flag ^ -1;
            if (flag == 4) {
                itemHolderInfo = record.preInfo;
            } else if (flag == 8) {
                itemHolderInfo = record.postInfo;
            } else {
                throw new IllegalArgumentException("Must provide flag PRE or POST");
            }
            if ((record.flags & 12) == 0) {
                this.mLayoutHolderMap.removeAt(index);
                InfoRecord.recycle(record);
            }
        }
    }
    return itemHolderInfo;
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:23,代碼來源:ViewInfoStore.java

示例6: onCreateViewHolder

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View v = null;
    ViewHolder viewHolder = null;
    if (viewType == TYPE_COLOR) {
        v = LayoutInflater.from(parent.getContext()).inflate(
                R.layout.view_color_panel, parent,false);
        viewHolder = new ColorViewHolder(v);
    } else if (viewType == TYPE_MORE) {
        v = LayoutInflater.from(parent.getContext())
                .inflate(R.layout.view_color_more_panel,parent,false);
        viewHolder = new MoreViewHolder(v);
    }

    return viewHolder;
}
 
開發者ID:viseator,項目名稱:MontageCam,代碼行數:17,代碼來源:ColorListAdapter.java

示例7: onCreateViewHolder

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {

    if (viewType == ITEM_TYPE_HEADER) {
        return new HeaderBottomHolder(recyclerViewHeader);
    } else if (viewType == ITEM_TYPE_CONTENT) {
        return adapter.onCreateViewHolder(parent, viewType);
    } else if (viewType == ITEM_TYPE_BOTTOM) {
        return new HeaderBottomHolder(recyclerViewFooter);
    } else if (viewType == ITEM_TYPE_HEADERVIEW) {
        return new HeaderBottomHolder(headerView);
    } else if (viewType == ITEM_TYPE_FOOTVIEW) {
        return new HeaderBottomHolder(footView);
    }
    return adapter.onCreateViewHolder(parent, viewType);
}
 
開發者ID:ivy5,項目名稱:xrecyclerview,代碼行數:17,代碼來源:RecyclerViewAdapter.java

示例8: process

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
void process(ProcessCallback callback) {
    for (int index = this.mLayoutHolderMap.size() - 1; index >= 0; index--) {
        ViewHolder viewHolder = (ViewHolder) this.mLayoutHolderMap.keyAt(index);
        InfoRecord record = (InfoRecord) this.mLayoutHolderMap.removeAt(index);
        if ((record.flags & 3) == 3) {
            callback.unused(viewHolder);
        } else if ((record.flags & 1) != 0) {
            if (record.preInfo == null) {
                callback.unused(viewHolder);
            } else {
                callback.processDisappeared(viewHolder, record.preInfo, record.postInfo);
            }
        } else if ((record.flags & 14) == 14) {
            callback.processAppeared(viewHolder, record.preInfo, record.postInfo);
        } else if ((record.flags & 12) == 12) {
            callback.processPersistent(viewHolder, record.preInfo, record.postInfo);
        } else if ((record.flags & 4) != 0) {
            callback.processDisappeared(viewHolder, record.preInfo, null);
        } else if ((record.flags & 8) != 0) {
            callback.processAppeared(viewHolder, record.preInfo, record.postInfo);
        } else if ((record.flags & 2) != 0) {
        }
        InfoRecord.recycle(record);
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:26,代碼來源:ViewInfoStore.java

示例9: endChangeAnimationIfNecessary

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
開發者ID:angcyo,項目名稱:RLibrary,代碼行數:17,代碼來源:BaseItemAnimator.java

示例10: onLongPress

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
public void onLongPress(MotionEvent e) {
    View child = ItemTouchHelper.this.findChildView(e);
    if (child != null) {
        ViewHolder vh = ItemTouchHelper.this.mRecyclerView.getChildViewHolder(child);
        if (vh != null && ItemTouchHelper.this.mCallback.hasDragFlag(ItemTouchHelper.this.mRecyclerView, vh) && MotionEventCompat.getPointerId(e, 0) == ItemTouchHelper.this.mActivePointerId) {
            int index = MotionEventCompat.findPointerIndex(e, ItemTouchHelper.this.mActivePointerId);
            float x = MotionEventCompat.getX(e, index);
            float y = MotionEventCompat.getY(e, index);
            ItemTouchHelper.this.mInitialTouchX = x;
            ItemTouchHelper.this.mInitialTouchY = y;
            ItemTouchHelper itemTouchHelper = ItemTouchHelper.this;
            ItemTouchHelper.this.mDy = 0.0f;
            itemTouchHelper.mDx = 0.0f;
            if (ItemTouchHelper.this.mCallback.isLongPressDragEnabled()) {
                ItemTouchHelper.this.select(vh, 2);
            }
        }
    }
}
 
開發者ID:JackChan1999,項目名稱:boohee_v5.6,代碼行數:20,代碼來源:ItemTouchHelper.java

示例11: onViewRecycled

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@SuppressWarnings("unchecked")
@Override
public final void onViewRecycled(ViewHolder holder) {
  if (!(holder instanceof HeaderFooterViewHolder)) {
    onItemViewRecycled((VH)holder);
  }
}
 
開發者ID:CableIM,項目名稱:Cable-Android,代碼行數:8,代碼來源:CursorRecyclerViewAdapter.java

示例12: ChangeInfo

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private ChangeInfo(ViewHolder oldHolder, ViewHolder newHolder,
                   int fromX, int fromY, int toX, int toY) {
    this(oldHolder, newHolder);
    this.fromX = fromX;
    this.fromY = fromY;
    this.toX = toX;
    this.toY = toY;
}
 
開發者ID:XndroidDev,項目名稱:Xndroid,代碼行數:9,代碼來源:HorizontalItemAnimator.java

示例13: callBack

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
private void callBack(OnGridItemMoveListener listener, ViewHolder viewHolder, int fromPos, ViewHolder target, int toPos, boolean addFirst, boolean isLast) {
    if (isLast || addFirst) {
        listener.onItemMove(fromPos, toPos, addFirst, isLast);
    } else if (viewHolder.getItemViewType() == target.getItemViewType()) {
        listener.onItemMove(fromPos, toPos, false, false);
    }
}
 
開發者ID:JackChan1999,項目名稱:letv,代碼行數:8,代碼來源:ItemDragHelperCallback.java

示例14: onMove

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
/**
 * If this method returns true, ItemTouchHelper assumes viewHolder has been
 * moved to the adapter position of target ViewHolder
 * @param recyclerView
 * @param viewHolder
 * @param target
 * @return
 */
@Override
public boolean onMove(RecyclerView recyclerView,
                      ViewHolder viewHolder,
                      ViewHolder target) {
    int toPosition = target.getAdapterPosition();
    mListener.onItemMove(viewHolder.getAdapterPosition(), toPosition);

    draggedTo = toPosition;

    return true;
}
 
開發者ID:kiwiandroiddev,項目名稱:starcraft-2-build-player,代碼行數:20,代碼來源:SimpleItemTouchCallback.java

示例15: animateRemove

import android.support.v7.widget.RecyclerView.ViewHolder; //導入依賴的package包/類
@Override
/** Override prepHolderForAnimateRemove
 *
 * Called when an item is removed from the RecyclerView. Implementors can choose
 * whether and how to animate that change, but must always call
 * {@link #dispatchRemoveFinished(ViewHolder)} when done, either
 * immediately (if no animation will occur) or after the animation actually finishes.
 * The return value indicates whether an animation has been set up and whether the
 * ItemAnimators {@link #runPendingAnimations()} method should be called at the
 * next opportunity. This mechanism allows ItemAnimator to set up individual animations
 * as separate calls to {@link #animateAdd(H) animateAdd()},
 * {@link #animateMove(ViewHolder, int, int, int, int) animateMove()}, and
 * {@link #animateRemove(ViewHolder) animateRemove()} come in one by one, then
 * start the animations together in the later call to {@link #runPendingAnimations()}.
 *
 * <p>This method may also be called for disappearing items which continue to exist in the
 * RecyclerView, but for which the system does not have enough information to animate
 * them out of view. In that case, the default animation for removing items is run
 * on those items as well.</p>
 *
 * @param holder The item that is being removed.
 * @return true if a later call to {@link #runPendingAnimations()} is requested,
 * false otherwise.
 */
public boolean animateRemove(final ViewHolder holder) {
	mPendingRemovals.add((H) holder);
	return prepHolderForAnimateRemove((H) holder);
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:29,代碼來源:PendingItemAnimator.java


注:本文中的android.support.v7.widget.RecyclerView.ViewHolder類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。