赞
踩
在项目开发过程中,我们有时会遇到需要控件闪烁和停止的问题。
MainActivity里的代码:
两个BUTTON一个TEXT
start=findViewById(R.id.button_start); stop=findViewById(R.id.button_stop); textdebug=findViewById(R.id.text_debug); start.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { startFlick(textdebug); } }); stop.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { stopFlick(textdebug); } });
xml文件:
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button_start" android:text="开始"/> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/button_stop" android:text="停止"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/text_debug" android:text="控件闪烁测试" android:textSize="22dp" android:gravity="center" android:background="@color/red" android:textColor="@color/black"/>
/**开启View闪烁效果**/ public void startFlick( View view ) { if (null == view) { return; } Animation alphaAnimation = new AlphaAnimation(1, 0); alphaAnimation.setDuration(300); alphaAnimation.setInterpolator(new LinearInterpolator()); alphaAnimation.setRepeatCount(Animation.INFINITE); alphaAnimation.setRepeatMode(Animation.REVERSE); view.startAnimation(alphaAnimation); } /**取消View闪烁效果**/ public void stopFlick( View view ) { if (null == view) { return; } view.clearAnimation(); }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。