Android animation and setBackroundResource conflict?



I have a GridView with items that change background resource when an item is clicked. At the same time I want to animate a layouts position, when I do this however, the background resource for gridView item doesn't change the first time the animation is played


What i want to happen: item is clicked 1. item backgroundResource is changed 2.a hidden layout is shown and animated


what actually seems to be happening is:


First time when the layout is still hidden the animation is shown but the background resource of the clicked item is not changed, any subsequent item clicks set the resource as it should and the animation works.


this is the onItemClickListener:



gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View v, int position, long id) {

scaleAnimateHeight(findViewById(R.id.dateDetailContainer));
setSelectedBackground(v, gridview);
}


scaleAnimateHeight():



private void scaleAnimateHeight(View v){
LinearLayout tv = (LinearLayout) v;
tv.setVisibility(View.VISIBLE);
Animation expand = AnimationUtils.loadAnimation(this, R.anim.from_left);
tv.startAnimation(expand);
}


setSelectedBackground():



private void setSelectedBackground(View v, GridView gridview ){
v.setBackgroundResource(R.drawable.back_selected);
}


anim.from_left.xml:



<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://ift.tt/nIICcg">
<translate xmlns:android="http://ift.tt/nIICcg"
android:duration="250"
android:fromXDelta="-100%"
android:toXDelta="0%" >
</translate>
</set>


and the layout:



<LinearLayout
android:id="@+id/dateDetailContainer"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is a Placeholder"
android:textSize="15sp"
/>

</LinearLayout>

No comments:

Post a Comment