我已经使用ViewFlipper
control 来显示具有连续间隔的推文left to right
。我在 ViewFlipper 中为每条推文添加了动态文本视图。
一切正常,但有时 textview 重叠。
这种奇怪行为的原因是什么?
代码:
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 :
这是显示上述问题的另一个快照..