22
33import android .animation .ValueAnimator ;
44import android .content .Context ;
5+ import android .content .res .TypedArray ;
56import android .database .DataSetObserver ;
67import android .support .v4 .view .GestureDetectorCompat ;
78import android .support .v4 .widget .ViewDragHelper ;
@@ -42,6 +43,8 @@ public class CardStackView extends ViewGroup {
4243
4344 private boolean mSkipLayout = false ;
4445 private boolean mSkipTouch = false ;
46+ private int mCardHeight ;
47+ private int mCardMinSpan ;
4548
4649 public void setSkipLayout (boolean skipLayout ) {
4750 mSkipLayout = skipLayout ;
@@ -62,6 +65,11 @@ public CardStackView(Context context, AttributeSet attrs) {
6265 public CardStackView (Context context , AttributeSet attrs , int defStyleAttr ) {
6366 super (context , attrs , defStyleAttr );
6467
68+ TypedArray ta = getContext ().getTheme ().obtainStyledAttributes (attrs , R .styleable .CardStackView , defStyleAttr , 0 );
69+ mCardHeight = ta .getDimensionPixelSize (R .styleable .CardStackView_card_height , Util .dp2px (getContext (), 160 ));
70+ mCardMinSpan = ta .getDimensionPixelSize (R .styleable .CardStackView_card_min_span , Util .dp2px (getContext (), 40 ));
71+ ta .recycle ();
72+
6573 initTouchCallback ();
6674
6775 setChildrenDrawingOrderEnabled (true );
@@ -195,11 +203,10 @@ private void updateOptions() {
195203 int parentH = getMeasuredHeight () - getPaddingTop () - getPaddingBottom ();
196204 int parentW = getMeasuredWidth () - getPaddingLeft () - getPaddingRight ();
197205
198- // TODO: 2016/10/31 后面提供相关属性,不通过 adapter 提供
199- mOptions .CARD_HEIGHT = mCardAdapter .getCardHeight ();
206+ mOptions .CARD_HEIGHT = mCardHeight ;
200207 mOptions .CARD_WIDTH = parentW ;
201208
202- mOptions .CARD_SPAN_NORMAL_MIN = mCardAdapter . getMinCardSpan () ;
209+ mOptions .CARD_SPAN_NORMAL_MIN = mCardMinSpan ;
203210 int span = (parentH - mOptions .CARD_HEIGHT ) / (mCardAdapter .getItemCount () - 1 );
204211 mOptions .CARD_SPAN_NORMAL = Math .max (span , mOptions .CARD_SPAN_NORMAL_MIN );
205212
0 commit comments