如何避免选择,而在Android的拖动图像画廊 [英] How to avoid selector while dragging image in Gallery in Android
问题描述
我有一系列的照片显示的图像。当用户点击一个,他们被带到不同的看法。
我想给一些反馈给用户,当他们执行的点击,就在视图更改之前。
I have a series of images shown in a Gallery. WHen the user clicks on one, they are taken to a different view. I want to give some feedback to the user when they perform the click, just before the view changes.
因此,我定义了一个选择:
I defined a selector thus:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true" android:drawable="@drawable/pic_frame_pressed" />
<item android:drawable="@drawable/pic_frame" /> <!-- default -->
</selector>
这工作。当用户点击图像上在显示一帧的画廊...
This works. When the user clicks on an image in the gallery a frame is displayed...
但是,它也示出当用户拖动画廊背部和使用图像脱颖而出。
But, it is also shown when the user is dragging the gallery back and fore using an image.
我看了看不同的状态,我可以找到一个选择:
I looked at the different states I could find for a selector:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:color="hex_color"
android:state_pressed=["true" | "false"]
android:state_focused=["true" | "false"]
android:state_selected=["true" | "false"]
android:state_checkable=["true" | "false"]
android:state_checked=["true" | "false"]
android:state_enabled=["true" | "false"]
android:state_window_focused=["true" | "false"] />
</selector>
和我想他们也没有找到一个组合,只有当用户在图像上单击射击(选中总是如火灾因为这是在画廊中心的图像)
and I tried them but couldn't find a combination that only fired when the user clicked on the image (e.g. "selected" always fires for the image that is in the center of the Gallery)
我需要一种state_clicked...
I need a kind of "state_clicked"...
推荐答案
我在这里遇到了同样的情况
我发现的唯一的解决办法是处理后台切换自己的OnItemClick事件(这是不优雅:/):
I face the same situation here
The only solution I found is to handle the background switch myself on the OnItemClick event (which is not elegant :/) :
mGallery.setOnItemClickListener(new OnItemClickListener(){
@Override
public void onItemClick(AdapterView<?> parent, View clickedView, int position, long id) {
for(int i = 0; i < parent.getChildCount(); i++){
parent.getChildAt(i).setBackgroundResource(R.drawable.bg_menu);
((TextView) parent.getChildAt(i)).setTextColor(getResources().getColor(R.color.white));
}
clickedView.setBackgroundResource(R.drawable.bg_menu_selected);
((TextView) clickedView).setTextColor(getResources().getColor(R.color.dark_blue));
((SectionAdapter) mGallery.getAdapter()).setSelected(position);
}
});
正如你可以看到我所选择的位置存储我的适配器上,以显示与当他们重绘(失去焦点)正确的布局
项目
我真的很想找到另一种解决办法,但我还不
如果有人得到了它,我会很高兴地听到:D
As you can see I store the selected position on my adapter in order to display the items with the correct layout when they are redraw (lose focus)
I really wanted to find another solution but I don't yet
If anyone got it I'll be pleased to hear :D
这篇关于如何避免选择,而在Android的拖动图像画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!