Last active
August 29, 2015 14:16
-
-
Save amyu/cd742fbf5803b3e83d9a to your computer and use it in GitHub Desktop.
Touch座標からIndexとるやつ
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context; | |
import android.graphics.Rect; | |
import android.util.AttributeSet; | |
import android.widget.ListView; | |
/** | |
* Created by amyu on 15/02/28. | |
*/ | |
public class HitRectListView extends ListView { | |
public HitRectListView(Context context) { | |
super(context); | |
} | |
public HitRectListView(Context context, AttributeSet attrs) { | |
super(context, attrs); | |
} | |
public HitRectListView(Context context, AttributeSet attrs, int defStyleAttr) { | |
super(context, attrs, defStyleAttr); | |
} | |
public HitRectListView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { | |
super(context, attrs, defStyleAttr, defStyleRes); | |
} | |
public int getTouchChildIndex(final int x, final int y) { | |
int childCount = getChildCount(); | |
Rect rect = new Rect(); | |
for (int index = 0; index < childCount; index++) { | |
getChildAt(index).getHitRect(rect); | |
if (rect.contains(x, y)) { | |
return index; | |
} | |
} | |
return -1; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment