Skip to content

Commit 24b4646

Browse files
committed
修复android4.0以下bug,zorder 为空问题
1 parent 4fa1596 commit 24b4646

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

lib/src/main/java/org/evilbinary/tv/widget/TvZorderRelativeLayout.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.evilbinary.tv.widget;
22

33
import android.content.Context;
4+
import android.os.Build;
45
import android.util.AttributeSet;
56
import android.view.KeyEvent;
67
import android.view.View;
@@ -30,20 +31,25 @@ public void setCurrentPosition(int pos) {
3031

3132
@Override
3233
public boolean dispatchKeyEvent(KeyEvent event) {
33-
34-
View focused=findFocus();
35-
int pos = indexOfChild(focused);
36-
if (pos >= 0 && pos < getChildCount() ) {
37-
setCurrentPosition(pos);
38-
postInvalidate();
34+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.JELLY_BEAN_MR2) {
35+
View focused = findFocus();
36+
int pos = indexOfChild(focused);
37+
if (pos >= 0 && pos < getChildCount()) {
38+
setCurrentPosition(pos);
39+
postInvalidate();
40+
}
3941
}
4042

4143
return super.dispatchKeyEvent(event);
4244
}
4345

4446
@Override
4547
protected int getChildDrawingOrder(int childCount, int i) {
46-
48+
View v = getFocusedChild();
49+
int pos = indexOfChild(v);
50+
if (pos >= 0 && pos < childCount)
51+
setCurrentPosition(pos);
52+
4753
if (i == childCount - 1) {//这是最后一个需要刷新的item
4854
return position;
4955
}

0 commit comments

Comments
 (0)