ImageButton动态旋转效果
来源:互联网 发布:最优化理论与算法ppt 编辑:程序博客网 时间:2024/06/04 17:57
1、首先在res/anim下新建一个rotate.xml
<?xml version="1.0" encoding="utf-8"?><rotate xmlns:android="http://schemas.android.com/apk/res/android" android:fromDegrees="0" android:toDegrees="36000" android:toYScale="0.0" android:pivotX="50%" android:pivotY="50%" android:duration="1000" />
其中toDegrees是旋转圈数,pivotX和privotY是以(x,y)点旋转,duration是速度。
2、重写ImageButton类,命名为MyCustomButton.java
public class MyCustomButton extends ImageButton{private static String TAG = "HIPPO_DEBUG";private Animation buttonAnimation;public MyCustomButton(Context context){super(context);// TODO Auto-generated constructor stubbuttonAnimation = AnimationUtils.loadAnimation(this.getContext(),R.anim.rotate);this.setOnTouchListener(new OnTouchListener(){@Overridepublic boolean onTouch(View v, MotionEvent event){// TODO Auto-generated method stubLog.i(TAG, "MyCustomButton onTouchListener()");MyCustomButton.this.startAnimation(buttonAnimation);return false;}});/* * No Use for Custom onClickListener() this.setOnClickListener(new * OnClickListener() { * * @Override public void onClick(View v) { // TODO Auto-generated method * stub MyCustomButton.this.startAnimation(buttonAnimation); } }); */}public MyCustomButton(Context context, AttributeSet attrs, int defStyle){super(context, attrs, defStyle);// TODO Auto-generated constructor stub}public MyCustomButton(Context context, AttributeSet attrs){super(context, attrs);// TODO Auto-generated constructor stub}/* * 扩展学习 * * @Override public boolean onTouchEvent(MotionEvent event) { // TODO * Auto-generated method stub Log.i(TAG, "MyCustomButton onTouchEvent()"); * return super.onTouchEvent(event); } */}
3、xml的布局文件
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="fill_parent" android:layout_height="fill_parent" tools:context=".MainActivity" ><LinearLayout android:layout_height="wrap_content" android:layout_width="wrap_content" android:layout_alignParentBottom="true" android:orientation="horizontal"> <LinearLayout android:id="@+id/layout1" android:layout_height="80dp" android:layout_width="80dp" android:orientation="horizontal"></LinearLayout> <LinearLayout android:id="@+id/layout2" android:layout_height="80dp" android:layout_width="80dp" android:orientation="horizontal"></LinearLayout> <LinearLayout android:id="@+id/layout3" android:layout_height="80dp" android:layout_width="80dp" android:orientation="horizontal"></LinearLayout> <LinearLayout android:id="@+id/layout4" android:layout_height="80dp" android:layout_width="80dp" android:orientation="horizontal"></LinearLayout> </LinearLayout></RelativeLayout>
4、创建和使用按钮,以其中一个为例
mLinearLayout1 = (LinearLayout) findViewById(R.id.layout1);LinearLayout.LayoutParams llp1 = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.FILL_PARENT,LinearLayout.LayoutParams.WRAP_CONTENT);mImageButton1 = new MyCustomButton(MainActivity.this);mLinearLayout1.addView(mImageButton1, llp1);mImageButton1.setImageDrawable(getResources().getDrawable(R.drawable.open));
- ImageButton动态旋转效果
- ImageButton添加鼠标效果
- 动态改变ImageButton背景图片
- Android摄像头开发完美demo---(循环聚焦,缩放大小,旋转picture,查询支持的picturesize, ImageButton按键效果)
- 【转】Android摄像头开发完美demo---(循环聚焦,缩放大小,旋转picture,查询支持的picturesize, ImageButton按键效果)
- ImageButton按下效果设计
- 设置ImageButton的点击效果
- ImageButton单击切换图片效果
- android view(image,imageButton,...)的旋转
- CSS3实现一个鼠标跟随动态旋转效果
- ImageButton动态改变按钮图片
- 2013新春奉送:Android摄像头开发完美demo---(循环聚焦,缩放大小,旋转picture,查询支持的picturesize, ImageButton按键效果)
- 2013新春奉送:Android摄像头开发完美demo---(循环聚焦,缩放大小,旋转picture,查询支持的picturesize, ImageButton按键效果)
- 动态旋转
- Android ImageButton 如何实现一个点击效果
- Android中的Button、ImageButton自定义点击效果
- Android中ImageButton实现“按下”效果
- 头像选择效果(ImageButton,Gallery,ImageSwitcher)
- CVPR2013感兴趣的文章整理
- IOS 自定义字体
- 深入理解Java内存模型(五)——锁
- 64位驱动开发及驱动签名
- C++lambda表达式权威指南
- ImageButton动态旋转效果
- A 星寻路算法实现的细节
- 分布式数据库系统
- CSS的z-index设置不生效的原因
- 使用srvany.exe将任何程序作为Windows服务运行
- 深入理解Java内存模型(六)——final
- EAS BOS 实现自动换行
- 瑞萨借SuperH系列在电机控制领域表现优异
- 通过当前日期获取周初、月初、月末日期