Skip to content

Commit 5974d3f

Browse files
committed
修复部分bug
1 parent b0d7408 commit 5974d3f

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

readme.md

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66

77
- 测试版本4.1.2,4.2.2,4.4.2可用
88

9+
##2014-9-11修改
10+
11+
- 修复设置高度`wrap_content`时显示不全的bug
12+
- 修复点击后,翻转过程中向下滑动出现的bug
13+
14+
>注意:如果设置高度为`wrap_content`,为了保证动画视觉上的完整性,需要设置自身及所有关联窗口的`android:clipChildren`属性为false(代码中setClipChildren(false))。
15+
916
##使用
1017

1118

@@ -23,7 +30,5 @@
2330

2431
##问题
2532

26-
- `CardView`高度设置为`wrap_content`卡片会显示不全。(已修复)
27-
- `CardView`设置`padding``margin`,旋转动画会有被截断的效果。最后一张卡片距离顶部的距离是在CardView内部指定的,为固定值。
2833
- 测试2.3.2有严重bug(估计4.0版本之前都有此bug),不可用。
2934

res/layout/activity_main.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@
44
android:layout_height="match_parent"
55
tools:context="com.chiemy.cardview.MainActivity"
66
android:background="#00688B"
7+
android:clipChildren="false"
78
>
89

910
<com.chiemy.cardview.view.CardView
1011
android:id="@+id/cardView1"
1112
android:layout_width="match_parent"
12-
android:layout_height="match_parent"
13+
android:layout_height="wrap_content"
1314
>
1415
</com.chiemy.cardview.view.CardView>
1516

src/com/chiemy/cardview/view/CardView.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,10 @@
44
import android.database.DataSetObserver;
55
import android.graphics.Rect;
66
import android.util.AttributeSet;
7-
import android.util.Log;
87
import android.util.SparseArray;
98
import android.view.MotionEvent;
109
import android.view.View;
1110
import android.view.ViewConfiguration;
12-
import android.view.ViewGroup;
13-
import android.view.View.MeasureSpec;
1411
import android.view.animation.AccelerateInterpolator;
1512
import android.widget.FrameLayout;
1613
import android.widget.ListAdapter;
@@ -107,7 +104,6 @@ && getChildCount() < mMaxVisible) {
107104
final View view = mListAdapter.getView(mNextAdapterPosition,
108105
convertView, this);
109106
view.setOnClickListener(null);
110-
// view.setOnTouchListener(null);
111107
viewHolder.put(index, view);
112108

113109
// 添加剩余的View时,始终处在最后
@@ -173,17 +169,13 @@ protected void onLayout(boolean changed, int left, int top, int right,
173169
}
174170

175171
float downX, downY;
176-
boolean remove = false;
177172

178173
@Override
179174
public boolean onTouchEvent(MotionEvent event) {
180175
switch (event.getAction()) {
181176
case MotionEvent.ACTION_MOVE:
182-
if (!remove) {
183-
if (goDown()) {
184-
downY = -1;
185-
remove = true;
186-
}
177+
if (goDown()) {
178+
downY = -1;
187179
}
188180
break;
189181
}
@@ -195,12 +187,16 @@ public boolean onTouchEvent(MotionEvent event) {
195187
*/
196188
private boolean goDown() {
197189
final View topView = getChildAt(getChildCount() - 1);
190+
if(!topView.isClickable()){
191+
return false;
192+
}
198193
// topView.getHitRect(topRect); 在4.3以前有bug,用以下方法代替
199194
topRect = getHitRect(topRect, topView);
200195
// 如果按下的位置不在顶部视图上,则不移动
201196
if (!topRect.contains((int) downX, (int) downY)) {
202197
return false;
203198
}
199+
topView.setClickable(false);
204200
ViewPropertyAnimator anim = ViewPropertyAnimator
205201
.animate(topView)
206202
.translationY(
@@ -210,6 +206,7 @@ private boolean goDown() {
210206
anim.setListener(new AnimatorListenerAdapter() {
211207
@Override
212208
public void onAnimationEnd(Animator animation) {
209+
topView.setClickable(true);
213210
removeView(topView);
214211
ensureFull();
215212
final int count = getChildCount();
@@ -245,6 +242,7 @@ public void onAnimationEnd(Animator animation) {
245242
* @param view
246243
*/
247244
private void bringToTop(final View view) {
245+
topPosition++;
248246
float scaleX = ViewHelper.getScaleX(view) + ((float) 1 / mMaxVisible)
249247
* 0.2f;
250248
float tranlateY = ViewHelper.getTranslationY(view) + itemSpace;
@@ -253,8 +251,7 @@ private void bringToTop(final View view) {
253251
.setInterpolator(new AccelerateInterpolator())
254252
.setListener(null).setListener(new AnimatorListenerAdapter() {
255253
public void onAnimationEnd(Animator animation) {
256-
topPosition++;
257-
remove = false;
254+
258255
}
259256
});
260257
}

0 commit comments

Comments
 (0)