ron*_*ron 41 android android-button android-gesture
在代码中,是否有任何方法可以使按钮持续闪烁,然后在按下时停止闪烁?
Ale*_*lov 118
有几种,取决于你的意思是什么样的闪烁.例如,您可以使用alpha动画并在首次出现按钮时启动它.当用户点击按钮时,就在你OnClickListener
刚刚做的时候clearAnimation()
.
例:
public void onCreate(Bundle savedInstanceState) {
final Animation animation = new AlphaAnimation(1, 0); // Change alpha from fully visible to invisible
animation.setDuration(500); // duration - half a second
animation.setInterpolator(new LinearInterpolator()); // do not alter animation rate
animation.setRepeatCount(Animation.INFINITE); // Repeat animation infinitely
animation.setRepeatMode(Animation.REVERSE); // Reverse animation at the end so the button will fade back in
final Button btn = (Button) findViewById(R.id.your_btn);
btn.startAnimation(animation);
btn.setOnClickListener(new OnClickListener() {
@Override
public void onClick(final View view) {
view.clearAnimation();
}
});
}
Run Code Online (Sandbox Code Playgroud)
Dee*_*rma 12
您可以使用此代码,也可以通过mAnimation.setDuration(200)决定按钮的闪烁时间 ; .代码如下.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
select=(Button)findViewById(R.id.bSelect);
Animation mAnimation = new AlphaAnimation(1, 0);
mAnimation.setDuration(200);
mAnimation.setInterpolator(new LinearInterpolator());
mAnimation.setRepeatCount(Animation.INFINITE);
mAnimation.setRepeatMode(Animation.REVERSE);
select.startAnimation(mAnimation);
select.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
v.clearAnimation();
}
});
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
41242 次 |
最近记录: |