The problem of overlapping text in ViewFlipper.

I used the ViewFlipper element to display tweets with a continuous interval from left to right . I added dynamic text for each tweet in ViewFlipper.

Everything works well, but sometime the text overlaps. enter image description here

What is the 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 that shows the above problems.

enter image description here

+4
source share
4 answers

I had the same problem using ViewFlipper and onFling Gesture on some devices with my application.

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

 android:background="#000000" 

This behavior still seems weird, and I'm not quite sure why this is fixed. Perhaps this has something to do with transparency.

+2
source

I had the same problem using ViewFlipper. I will explain the reason, look at the wrong code:

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

in my case, listview addHeader (ViewFlipper)

+1
source

Try

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

Use FILL_PARENT instead of WRAP_CONTENT

Worked well for me.

0
source

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

Just make sure the flipInterval time is longer than the animation time.

Help him help.

0
source

Source: https://habr.com/ru/post/1441972/


All Articles