Android アプリケーションでニュース バーを作成したいと考えています。アニメーションを使用して TextView を左から右に移動し、文字列の配列から新しいテキストを各ラウンドに入力しました。私は多くの問題に直面し、5 つ以上の方法を使用しましたが、それぞれの動作が悪いです。主な問題は、アニメーションが終了すると textView が更新され、ユーザーフレンドリーな動作ではない点滅のように見えることです。
コード スニペットを次に示します。
TextView my_text;
Animation slideRight;
Animation slideLeft;
String [] text = {"TwoOneOneOneOneOneOneOneOneOneTwo","OneTwoTwoTwoTwoTwoTwoTwoTwoTwoTwoOne",
"OneThreeThreeThreeThreeThreeThreeThreeOne","OneFourFourFourFourFourFourFourOne",
"OneFiveFiveFiveFiveFiveFiveFiveOne","OneSixSixSixSixSixSixSixOne",
"OneSevenSevenSevenSevenSevenSevenSeveOne","OneEightEightEightEightEightEightEightOne",
"OneNineNineNineNineNineNineNineOne"};
int arr_length;
int count = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
arr_length = text.length;
slideRight = AnimationUtils.loadAnimation(this, android.R.anim.slide_out_right);
slideRight.setDuration(2000);
slideRight.setRepeatCount(Animation.INFINITE);
slideRight.setAnimationListener(slideRightListener);
slideLeft = AnimationUtils.loadAnimation(this, android.R.anim.slide_in_left);
slideLeft.setDuration(2000);
slideLeft.setAnimationListener(slideLeftListener);
my_text = (TextView) findViewById(R.id.textView1);
my_text.setVisibility(TextView.VISIBLE);
my_text.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), my_text.getText(), Toast.LENGTH_SHORT).show();
}
});
slideLeft.setAnimationListener(slideLeftListener);
my_text.startAnimation(slideLeft);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
AnimationListener slideLeftListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
my_text.startAnimation(slideRight);
}
};
AnimationListener slideRightListener = new AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
@Override
public void onAnimationRepeat(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
}
@Override
public void onAnimationEnd(Animation animation) {
my_text.setVisibility(TextView.VISIBLE);
if(count<arr_length)
{
my_text.setText(text[count]);
count+=1;
my_text.startAnimation(slideLeft);
}
else
{
count=0;
my_text.setText(text[count]);
my_text.startAnimation(slideLeft);
}
}
};
}