在其**onItemClick**
听众,你可以使用这样的**TransitionDrawable**
。我把这个代码放在getView()和highlightPosition是项目的位置。你可以根据你的需要修改它,并且reImage
是充气机xml上的相对布局。我已经把这段代码放在getView中。您可以尝试把它放在onItemClick..This代码突出显示所选择的项目2 3秒钟,然后颜色从蓝色渐变为白色: -
if(highlightPosition == position){
viewHolderThubnail.relImage.setBackgroundResource(R.drawable.translate);
TransitionDrawable transition = (TransitionDrawable) viewHolderThubnail.relImage.getBackground();
transition.startTransition(1000);
highlightPosition =-1;
}else{
viewHolderThubnail.relImage.setBackgroundResource(R.color.white);
}
translate.xml
<?xml version="1.0" encoding="UTF-8"?>
<transition xmlns:android="http://schemas.android.com/apk/res/android">
<!-- The drawables used here can be solid colors, gradients, shapes, images, etc. -->
<item android:drawable="@drawable/new_state" />
<item android:drawable="@drawable/original_state" />
</transition>
new_state.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#92BCE7"/>
</shape>
original_state.xml
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<solid android:color="#FFFFFF"/>
</shape>
说实话,我不太了解你的代码。我想更改特定项目的背景,而不是整个列表。如果我决定避免选择器可绘制,那么主要问题是获取项视图(特别是可以是ViewGroup),因为getChildAt()不是100%的证明。你的代码并不建议这样做。 – cyanide
我的代码更改所选项目的背景。您可以查看转换可绘制 –
TransitionDrawable不会自动选择所选项目,而您提供的代码部分不涉及OnItemClick参数(至少我看不到任何)。你能否提供更详细的代码? – cyanide