4

I've used ViewFlipper control to display tweets with continuous interval from left to right. I have added dynamic textview for each tweet in ViewFlipper.

All works good but sometime textview overlaps. enter image description here

Whats is a reason for this strange behavior?

Code:

for (int i = 0; i < tweets.length(); i++) {
            tweet = tweets.getJSONObject(i).getString("title")+"&nbsp;&nbsp; tweet on &nbsp;"+tweets.getJSONObject(i).getString("pubDate");         
            tv = new TextView(context);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.FILL_PARENT);
                params.weight = 1.0f;
                params.gravity=48;

            tv.setLayoutParams(params);
            tv.setGravity(Gravity.CENTER);

            tv.setTextSize(22);
            tv.setTextColor(ColorStateList.valueOf(Color.WHITE));
            tv.setSingleLine();

            //tv.setTextColor(getREs)
            tv.setText(tweet);
            flipper.addView(tv);
         }      

        flipper.setInAnimation(inFromRightAnimation(1500));        
        flipper.setOutAnimation(outToLeftAnimation(1500));
        flipper.startFlipping();



public static Animation inFromRightAnimation(int duration) {
        Animation inFromRight = new TranslateAnimation(
        Animation.RELATIVE_TO_PARENT,  +1.0f, Animation.RELATIVE_TO_PARENT,  0.0f,
        Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
        );
        inFromRight.setDuration(duration);
        inFromRight.setInterpolator(new AccelerateInterpolator());
        return inFromRight;
    }

public static Animation outToLeftAnimation(int duration) {
        Animation outtoLeft = new TranslateAnimation(
          Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,  -1.0f,
          Animation.RELATIVE_TO_PARENT,  0.0f, Animation.RELATIVE_TO_PARENT,   0.0f
        );      
        outtoLeft.setDuration(duration);
        outtoLeft.setInterpolator(new AccelerateInterpolator());
        return outtoLeft;
    }

EDIT :

Here is another snapshot which show above problem..

enter image description here

Swapnil Sonar
  • 2,232
  • 2
  • 29
  • 42

4 Answers4

3

I had the same issue using ViewFlipper and the onFling Gesture on some devices with my app.

By adding a background color to my view I was able to fix the problem. In my case it was the ListViews that were having the duplicated overlapped text, so I just added a black background in the xml of each ListView and it fixed the problem for me.

android:background="#000000"

This behavior still seems really strange and I'm not exactly sure why this fixed it. Maybe it had something to do with transparency.

redGREENblue
  • 3,076
  • 8
  • 39
  • 57
Isaac
  • 136
  • 1
  • 4
1

I had the same issue using ViewFlipper. I fnd the reason, look at the incorrect code:

public void setDuration(int ms) {
    mDurationTime = 1000*ms;
    this.setFlipInterval(mDurationTime);//don't do this
}

in my case, listview addHeader(ViewFlipper)

smottt
  • 3,272
  • 11
  • 37
  • 44
tikkate
  • 11
  • 1
  • The real reason is not the `setFlipInterval(mDurationTime)` method, it because the duration of `InAnimation` and `OutAnimation` is **shorter** than the flipInterval time. Just make sure the flipInterval time longer than animation time. – JohnWatsonDev Jul 13 '16 at 02:23
0

Try

LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
                    LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT);

Use FILL_PARENT instead of WRAP_CONTENT

Worked good for me.

catalin87
  • 625
  • 6
  • 19
0

It because the duration of InAnimation and OutAnimation is shorter than the flipInterval time.

Just make sure the flipInterval time longer than animation time.

Help it help.

JohnWatsonDev
  • 1,227
  • 9
  • 16