使用Animation实现控件抖动效果
来源:互联网 发布:阿里云改ssh端口 编辑:程序博客网 时间:2024/06/15 15:08
主要参考了官方ApiDemo里的Views/Animation/Shake的代码。设想一下,在EditText里用户输入的内容不符合规范或者密码错误的话,将该EditText抖动一下比弹出对话框有爱多了。
上代码:
res/anim/cycle_7.xml(实现抖动次数)
<?xml version="1.0" encoding="utf-8"?><cycleInterpolator xmlns:android="http://schemas.android.com/apk/res/android" android:cycles="7" />
<?xml version="1.0" encoding="utf-8"?><translate xmlns:android="http://schemas.android.com/apk/res/android" android:duration="1000" android:fromXDelta="0" android:interpolator="@anim/cycle_7" android:toXDelta="10" />
MainActivity.java
public class MainActivity extends Activity implements View.OnClickListener { @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.animation_1); View loginButton = findViewById(R.id.login); loginButton.setOnClickListener(this); } public void onClick(View v) { Animation shake = AnimationUtils.loadAnimation(this, R.anim.shake); findViewById(R.id.pw).startAnimation(shake); }}这里实现的是点击按钮,EditText实现抖动的效果。
布局文件:res/layout/animation_1.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:padding="10dip" android:layout_width="match_parent" android:layout_height="wrap_content"> <TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_marginBottom="10dip" android:text="@string/animation_1_instructions" /> <EditText android:id="@+id/pw" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" android:singleLine="true" android:password="true" /> <Button android:id="@+id/login" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/googlelogin_login" /></LinearLayout>当然这里是看不到抖动效果的……
![微笑](http://static.blog.csdn.net/xheditor/xheditor_emot/default/smile.gif)
0 0
- 使用Animation实现控件抖动效果
- 【Animation】实现某一个控件的抖动效果
- android控件实现抖动的效果
- 通用的Android控件抖动效果实现
- Android控件抖动效果
- android控件抖动效果
- android实现抖动效果
- EditText实现抖动效果
- 实现抖动效果
- CAKeyframeAnimation实现抖动效果
- android实现抖动效果
- jquery 实现抖动效果
- jquery 实现抖动效果
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Android中使用Animation实现控件的动画效果以及Interpolator和AnimationListener的使用
- Exception in thread "main" org.hibernate.InvalidMappingException: Unable to read XML
- IE6、IE7、IE8的CSS、JS兼容
- 百度系统工程师面试
- Unity3D随意截图并保存
- 软件产品测试概览
- 使用Animation实现控件抖动效果
- IOS 定位代码中崩溃位置
- Spring中如何配置Hibernate事务
- AFNetworking 学习笔记
- objective c之中的类和实例,方法等基本语法(一)
- 利用Linux命令按行去重以及按重复度排序
- FZOJ 1157 Crazy Tea Party
- CakePHP高级安装
- java从头学day01[准备工作]