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.
Whats is a reason for this strange behavior?
Code:
for (int i = 0; i < tweets.length(); i++) {
tweet = tweets.getJSONObject(i).getString("title")+" tweet on "+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..