@@ -58,16 +58,17 @@ public CardStackView(Context context, AttributeSet attrs, int defStyleAttr) {
5858 }
5959
6060 private void initViews () {
61+ mOptions = new Options ();
62+
6163 for (int i = 0 ; i < mCardAdapter .getItemCount (); i ++) {
6264 addView (mCardAdapter .getView (null , i , this ));
6365 }
64- mOptions = new Options ();
66+
67+ mSlidingResistanceCalculator = new SlidingResistanceCalculator (2000f , mOptions .CARD_SPAN_OFFSET );
6568
6669 updateOptions ();
6770
68- mCardFactory = new CardFactory (mOptions );
69- mCardFactory .init (this );
70- mSlidingResistanceCalculator = new SlidingResistanceCalculator (2000f , mOptions .CARD_SPAN_OFFSET );
71+ mCardFactory = new CardFactory (this , mOptions );
7172 //Log.d(TAG, "init: " + mCardAdapter.getItemCount());
7273 }
7374
@@ -169,7 +170,7 @@ public void onLongPress(MotionEvent e) {
169170 @ Override
170171 public boolean onSingleTapUp (MotionEvent e ) {
171172
172- CardHolder touch = mCardFactory .findByTouch (e .getY () - getPaddingTop ());
173+ final CardHolder touch = mCardFactory .findByTouch (e .getY () - getPaddingTop ());
173174 if (touch != null && mOnCardClickListener != null ) {
174175 mOnCardClickListener .onClick (touch .mView , touch .mRealIndex , touch .mChildIndex );
175176 }
@@ -183,12 +184,14 @@ public boolean onSingleTapUp(MotionEvent e) {
183184 * 计算一些常量值
184185 */
185186 private void updateOptions () {
186- mOptions .SCREEN_WIDTH = Util .getScreenWidthPixel (getContext ());
187+ int parentH = getMeasuredHeight () - getPaddingTop () - getPaddingBottom ();
188+ int parentW = getMeasuredWidth () - getPaddingLeft () - getPaddingRight ();
189+
190+ // TODO: 2016/10/31 后面提供相关属性,不通过 adapter 提供
187191 mOptions .CARD_HEIGHT = mCardAdapter .getCardHeight ();
188- mOptions .CARD_WIDTH = mOptions . SCREEN_WIDTH - getPaddingLeft () - getPaddingRight () ;
192+ mOptions .CARD_WIDTH = parentW ;
189193
190194 mOptions .CARD_SPAN_NORMAL_MIN = mCardAdapter .getMinCardSpan ();
191- int parentH = getMeasuredHeight () - getPaddingTop () - getPaddingBottom ();
192195 int span = (parentH - mOptions .CARD_HEIGHT ) / (mCardAdapter .getItemCount () - 1 );
193196 mOptions .CARD_SPAN_NORMAL = Math .max (span , mOptions .CARD_SPAN_NORMAL_MIN );
194197
@@ -241,7 +244,7 @@ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
241244 // wrap_content use min span
242245 if (existsValidChild ()) {
243246 width = maxWidth ;
244- height = mOptions .CARD_SPAN_NORMAL_MIN * (mCardFactory . size () - 1 ) + mOptions .CARD_HEIGHT ;
247+ height = mOptions .CARD_SPAN_NORMAL_MIN * (getChildCount () - 1 ) + mOptions .CARD_HEIGHT ;
245248 }
246249 width += (getPaddingLeft () + getPaddingRight ());
247250 height += (getPaddingTop () + getPaddingBottom ());
@@ -269,11 +272,14 @@ protected void onLayout(boolean changed, int left, int top, int right, int botto
269272 /**
270273 * 更新卡片位置
271274 */
272- private void updateCardPosition () {
275+ public void updateCardPosition () {
273276 if (!existsValidChild ()) return ;
274277
275278 for (int i = 0 ; i < mCardFactory .size (); i ++) {
276- mCardFactory .get (i ).layoutFixed ();
279+ CardHolder holder = mCardFactory .get (i );
280+ //if (!holder.isAnimating()) {
281+ holder .layoutFixed ();
282+ //}
277283 }
278284 }
279285
@@ -328,9 +334,6 @@ public interface OnPositionChangedListener {
328334 void onPositionChanged (List <Integer > position );
329335 }
330336
331-
332-
333-
334337 private class CardStackViewDataObserver extends DataSetObserver {
335338 @ Override
336339 public void onChanged () {
0 commit comments