Android TextView对象在ObjectAnimator启动之前可见
我正在尝试使用Android TextView对象在ObjectAnimator启动之前可见,android,textview,objectanimator,Android,Textview,Objectanimator,我正在尝试使用ObjectAnimator执行一个简单的动画。资料来源如下: TextView[] introTextViews = new TextView[] {(TextView) findViewById(R.id.intro_textView1_1), (TextView) findViewById(R.id.intro_textView1_2), (TextView) findViewById(R.id.intro_te
ObjectAnimator
执行一个简单的动画。资料来源如下:
TextView[] introTextViews = new TextView[] {(TextView) findViewById(R.id.intro_textView1_1),
(TextView) findViewById(R.id.intro_textView1_2),
(TextView) findViewById(R.id.intro_textView2_1),
(TextView) findViewById(R.id.intro_textView2_2),
(TextView) findViewById(R.id.intro_textView3_1),
(TextView) findViewById(R.id.intro_textView3_2),
(TextView) findViewById(R.id.intro_textView4_1),
(TextView) findViewById(R.id.intro_textView4_2)};
AnimatorSet animSet = new AnimatorSet();
ObjectAnimator[] animators = new ObjectAnimator[introTextViews.length];
for(int i=0; i<introTextViews.length; i++){
animators[i] = ObjectAnimator.ofFloat(introTextViews[i],
TextView.TRANSLATION_X, getResources().getDisplayMetrics().widthPixels,
0);
}
animSet.play(animators[0]).with(animators[1]); // Anim1
animSet.play(animators[2]).with(animators[3]).after(animators[0]); //Anim2
animSet.play(animators[4]).with(animators[5]).after(animators[2]); //Anim3
animSet.play(animators[6]).with(animators[7]).after(animators[4]); //Anim4
animSet.setDuration(6000);
animSet.setInterpolator(new AccelerateDecelerateInterpolator());
animSet.start();
TextView[]introTextViews=newtextView[]{(TextView)findViewById(R.id.intro_textView1_1),
(文本视图)findViewById(R.id.intro_textView1_2),
(TextView)findViewById(R.id.intro_TextView 2_1),
(文本视图)findViewById(R.id.intro_textView2_2),
(TextView)findViewById(R.id.intro_TextView 3_1),
(文本视图)findViewById(R.id.intro_文本视图3_2),
(TextView)findViewById(R.id.intro_TextView 4_1),
(TextView)findViewById(R.id.intro_TextView 4_2)};
AnimatorSet animSet=新的AnimatorSet();
ObjectAnimator[]animators=新的ObjectAnimator[introTextViews.length];
对于(int i=0;i最后我做了这个:
for(int i=0; i<introTextViews.length; i++){
//Add this line just to fix the animation initial X point
introTextViews[i].setX(getResources().getDisplayMetrics().widthPixels+10);
animators[i] = ObjectAnimator.ofFloat(introTextViews[i],
TextView.TRANSLATION_X, getResources().getDisplayMetrics().widthPixels,
0);
}
for(int i=0;i您的解决方案很好,您可以参考另一个解决方案:
在for循环中,通过setVisibility(View.Gone)将所有文本视图设置为不可见
,然后为每个动画师设置AnimatorListener
,并在动画开始时实现其,在那里设置相应的文本视图可见。我尝试的第一件事是!它也不起作用!动画开始时调用了该方法,但调用了最后3个动画(Anim2、Anim3、Anim4)实际上没有启动!是否希望其他文本视图在执行动画1时可见。否。我希望它们在开始时不可见。我希望它们在滑动动画完成后可见