Animation läuft nur manchmal

  • Antworten:1
Daniel online
  • Forum-Beiträge: 282

30.04.2012, 13:22:31 via Website

Hallo,

ich habe eine kleine Animation geschrieben, welche die ListView Items ausklappt.
Das funktioniert auch. Jedoch wird die Animation einfach nicht immer abgespielt. Es passiert manchmal, dass die Animation erst kommt, wenn ich die ListView scrolle! Ich kann dann solang warten wie ich will oder so oft draufklicken wie ich will. Die Animation kommt erst wenn ich scrolle.
Das ganze passiert auch nach einem mir nicht bekanntem System. Es funktioniert teilweise mehrmals hintereinander und dann auf einmal wieder nicht.

Hier meine Animation:
1public class AnimationListExpand extends Animation {
2 private View mAnimatedView;
3 private RelativeLayout.LayoutParams mViewLayoutParams;
4 private RelativeLayout parent;
5
6 private int maxHeight = 120;
7 /**
8 * Initialize the animation
9 * @param view The layout we want to animate
10 * @param duration The duration of the animation, in ms
11 */
12 public AnimationListExpand(View view, int duration) {
13
14 setDuration(duration);
15 mAnimatedView = view; //Der Tag des Views sagt aus ob die View expanded (true) oder collapsed (false) ist.
16 mViewLayoutParams = (RelativeLayout.LayoutParams) view.getLayoutParams();
17
18 }
19
20 @Override
21 protected void applyTransformation(float interpolatedTime, Transformation t) {
22 super.applyTransformation(interpolatedTime, t);
23
24 this.setAnimationListener(new AnimationListener() {
25
26 public void onAnimationStart(Animation animation) {
27 // TODO Auto-generated method stub
28
29 }
30
31 public void onAnimationRepeat(Animation animation) {
32 // TODO Auto-generated method stub
33
34 }
35
36 public void onAnimationEnd(Animation animation) {
37 if((Boolean)mAnimatedView.getTag()){
38 mAnimatedView.setTag(false);
39 mViewLayoutParams.height=0;
40 mAnimatedView.setLayoutParams(mViewLayoutParams);
41 mAnimatedView.requestLayout();
42 } else {
43 mAnimatedView.setTag(true);
44
45 mViewLayoutParams.height=maxHeight;
46 mAnimatedView.setLayoutParams(mViewLayoutParams);
47 mAnimatedView.requestLayout();
48 }
49
50 }
51 });
52
53 if((Boolean) mAnimatedView.getTag()==false){//ausfahren
54 if (interpolatedTime < 1.0f) {//Animation läuft
55 Log.d(TAG,"time="+interpolatedTime+ "height = "+(((double) interpolatedTime)*maxHeight));
56 if(mViewLayoutParams.height<maxHeight){
57 mViewLayoutParams.height=(int) ((double) interpolatedTime*maxHeight);
58 mAnimatedView.setLayoutParams(mViewLayoutParams);
59
60 // Invalidating the layout, making us seeing the changes we made
61 mAnimatedView.requestLayout();
62 }
63 }
64 } else if((Boolean) mAnimatedView.getTag()){//Einfahren
65 if (interpolatedTime < 1.0f) {//Animation läuft
66 if(mViewLayoutParams.height>0){
67 mViewLayoutParams.height=maxHeight-(int) ((double) interpolatedTime*maxHeight);
68 mAnimatedView.setLayoutParams(mViewLayoutParams);
69
70 // Invalidating the layout, making us seeing the changes we made
71 mAnimatedView.requestLayout();
72
73 }
74 }
75 }
76
77 }


Hier der Adapter in welchem auch der OnClickListener mit Animationsaufruf ist:

1class AdapterDay extends BaseAdapter{
2
3
4 public int getCount() {
5 return testFach.length;
6 }
7
8 public Object getItem(int position) {
9 return position;
10 }
11
12 public long getItemId(int position) {
13 return position;
14 }
15
16 public View getView(int position, View convertView, ViewGroup parent) {
17 CustomItem item;
18 if (convertView == null) {
19 item = new CustomItem(ctx, position);
20
21 } else {
22 item = (CustomItem) convertView;
23 }
24 item.setTitle(testFach[position]);
25 item.setTime(testZeit[position]);
26 item.setOnClickListener(new OnClickListener() {
27
28 public void onClick(View v) {
29 Log.d(TAG,"onClick");
30 View extention = v.findViewById(R.id.toolbar);
31 // Start the animation on the toolbar
32 extention.startAnimation(new AnimationListExpand(extention, 500));
33 }
34 });
35 return item;
36 }
37
38
39 }

Ich hoffe jemand kann mir hier vllt helfen.

Vielen Danke! :)

Antworten
Daniel online
  • Forum-Beiträge: 282

02.05.2012, 10:16:41 via Website

Kennt keiner ne Antwort?

Antworten