Android 在动态视图中只获得一次动画效果
我正在膨胀一个视图并将该视图放在另一个视图下方,一切都很好,但动画只是以所需的方式出现一次......当我再次按下按钮放置视图时,它不会像第一次出现的那样出现。
final Animation a3 = new AlphaAnimation(0.00f, 1.00f);
a3.setDuration(350);
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View cv = vi.inflate(R.layout.popupview, null);
final RelativeLayout rl = (RelativeLayout)findViewById(R.id.mainlayout);
final Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(cv!=null){
rl.removeView(cv);
}
RelativeLayout.LayoutParams innerLP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
cv.setLayoutParams(innerLP);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.BELOW, b1.getId());
cv.setLayoutParams(params1);
cv.startAnimation(a3);
rl.addView(cv);
rl.invalidate();
}
});
I am inflating a view and putting the view below another, everything is fine but the animation is just coming once in desired fashion...and when i again press the button to put the view its not coming the way it had appeared first time.
final Animation a3 = new AlphaAnimation(0.00f, 1.00f);
a3.setDuration(350);
LayoutInflater vi = (LayoutInflater) getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View cv = vi.inflate(R.layout.popupview, null);
final RelativeLayout rl = (RelativeLayout)findViewById(R.id.mainlayout);
final Button b1 = (Button)findViewById(R.id.button1);
b1.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
if(cv!=null){
rl.removeView(cv);
}
RelativeLayout.LayoutParams innerLP = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
cv.setLayoutParams(innerLP);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.BELOW, b1.getId());
cv.setLayoutParams(params1);
cv.startAnimation(a3);
rl.addView(cv);
rl.invalidate();
}
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
我之前也遇到过同样的问题...... 你可以检查我的帖子
当按下一次时它将开始动画..但是如果你想再次开始动画那么你应该让它停止。
I had gone through same problem before.... You can check my post
It will start animation when it pressed once..but if u want to start again the animation then you should make it stop.