仿乐安全首页动态效果
2015-01-25 20:20
344 查看
转载自:/article/1377979.html
![](http://img.blog.csdn.net/20140726211219127?watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvY2hkamo=/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/Center)
局:
[html] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/homepage_disk_button_orange_normal" />
<ImageView
android:id="@+id/iv_rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/homepage_disk_orange_normal" />
<com.example.view.RadiationView
android:id="@+id/rv"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="SB"
android:textColor="#ffffff"
android:textSize="30sp" />
</FrameLayout>
</LinearLayout>
旋转动画:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="12000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
带辐射效果的view:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
package com.example.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
/**
* @author Rowandjj
*
*带辐射效果的view
*/
public class RadiationView extends View
{
/**
*画笔
*/
private Paint mPaint = new Paint();
/**
*颜色
*/
private int mColor = 0x3f990e;
/**
* 透明度
*/
private int mAlpha = 60;
private Handler mHandler = null;
private static final int MESSAGE_DRAW = 0;
private static final String TAG = "RadiationView";
private int width;
private int height;
/**
* 扩散速度
*/
private int speed = 30;
/**
*最大辐射半径
*/
private int maxRadius = 100;
private int centerX;
private int centerY;
/**
* 最小半径
*/
private int minRadius = 70;
/**
* 当前半径
*/
private int radius = minRadius;
private boolean isStarted = false;
public RadiationView(Context context)
{
super(context);
init();
}
public RadiationView(Context context, AttributeSet attrs)
{
super(context, attrs, 0);
init();
}
public void startRadiate()
{
isStarted = true;
mHandler.sendEmptyMessage(MESSAGE_DRAW);
}
private void init()
{
mPaint = new Paint();
mPaint.setStrokeWidth(1);
//必须先设置color,再设置alpha
mPaint.setColor(mColor);
mPaint.setAlpha(mAlpha);
mHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
if(msg.what == MESSAGE_DRAW)
{
invalidate();
if(isStarted)
{
sendEmptyMessageDelayed(MESSAGE_DRAW,speed);
}
}
}
};
}
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom)
{
super.onLayout(changed, left, top, right, bottom);
width = this.getWidth();
height = this.getHeight();
if(width <= 0 || height<=0)
{
throw new RuntimeException("size illegal");
}
//中心点
centerX = width/2;
centerY = height/2;
//最大辐射半径
maxRadius = (width > height) ? height/2 : width/2;
Log.i(TAG,"MAX"+maxRadius);
if(maxRadius < 70)
{
throw new RuntimeException("size too small");
}
}
@Override
protected void onDraw(Canvas canvas)
{
mPaint.setColor(mColor);
mPaint.setAlpha(mAlpha);
if(radius <= 0)
{
return;
}
if(radius > maxRadius)
{
radius = minRadius;
}
canvas.save();
canvas.drawCircle(centerX, centerY, radius, mPaint);
canvas.restore();
radius += 1;
}
@Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
public void setColor(int color)
{
this.mColor = color;
}
public void setSpeed(int speed)
{
this.speed = speed;
}
public void setMinRadius(int radius)
{
this.minRadius = radius;
}
}
调用的代码:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
![](https://code.csdn.net/assets/ico_fork.svg)
package com.example.animdemo1;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import com.example.view.RadiationView;
public class MainActivity extends Activity
{
private ImageView iv = null;
private RadiationView rv = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv_rotate);
rv = (RadiationView) findViewById(R.id.rv);
rv.setMinRadius(70);//辐射半径
rv.startRadiate();//开始辐射
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_circle_anim);
iv.startAnimation(anim);//开始动画
}
}
局:
[html] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity" >
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/homepage_disk_button_orange_normal" />
<ImageView
android:id="@+id/iv_rotate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:src="@drawable/homepage_disk_orange_normal" />
<com.example.view.RadiationView
android:id="@+id/rv"
android:layout_width="250dp"
android:layout_height="250dp"
android:layout_gravity="center" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="SB"
android:textColor="#ffffff"
android:textSize="30sp" />
</FrameLayout>
</LinearLayout>
旋转动画:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
<?xml version="1.0" encoding="utf-8"?>
<rotate xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="12000"
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:startOffset="0"
android:interpolator="@android:anim/linear_interpolator"
android:repeatCount="infinite"
android:repeatMode="restart"
android:toDegrees="360" />
带辐射效果的view:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
package com.example.view;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.os.Handler;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;
/**
* @author Rowandjj
*
*带辐射效果的view
*/
public class RadiationView extends View
{
/**
*画笔
*/
private Paint mPaint = new Paint();
/**
*颜色
*/
private int mColor = 0x3f990e;
/**
* 透明度
*/
private int mAlpha = 60;
private Handler mHandler = null;
private static final int MESSAGE_DRAW = 0;
private static final String TAG = "RadiationView";
private int width;
private int height;
/**
* 扩散速度
*/
private int speed = 30;
/**
*最大辐射半径
*/
private int maxRadius = 100;
private int centerX;
private int centerY;
/**
* 最小半径
*/
private int minRadius = 70;
/**
* 当前半径
*/
private int radius = minRadius;
private boolean isStarted = false;
public RadiationView(Context context)
{
super(context);
init();
}
public RadiationView(Context context, AttributeSet attrs)
{
super(context, attrs, 0);
init();
}
public void startRadiate()
{
isStarted = true;
mHandler.sendEmptyMessage(MESSAGE_DRAW);
}
private void init()
{
mPaint = new Paint();
mPaint.setStrokeWidth(1);
//必须先设置color,再设置alpha
mPaint.setColor(mColor);
mPaint.setAlpha(mAlpha);
mHandler = new Handler()
{
public void handleMessage(android.os.Message msg)
{
if(msg.what == MESSAGE_DRAW)
{
invalidate();
if(isStarted)
{
sendEmptyMessageDelayed(MESSAGE_DRAW,speed);
}
}
}
};
}
@Override
protected void onLayout(boolean changed, int left, int top, int right,
int bottom)
{
super.onLayout(changed, left, top, right, bottom);
width = this.getWidth();
height = this.getHeight();
if(width <= 0 || height<=0)
{
throw new RuntimeException("size illegal");
}
//中心点
centerX = width/2;
centerY = height/2;
//最大辐射半径
maxRadius = (width > height) ? height/2 : width/2;
Log.i(TAG,"MAX"+maxRadius);
if(maxRadius < 70)
{
throw new RuntimeException("size too small");
}
}
@Override
protected void onDraw(Canvas canvas)
{
mPaint.setColor(mColor);
mPaint.setAlpha(mAlpha);
if(radius <= 0)
{
return;
}
if(radius > maxRadius)
{
radius = minRadius;
}
canvas.save();
canvas.drawCircle(centerX, centerY, radius, mPaint);
canvas.restore();
radius += 1;
}
@Override
protected void onAttachedToWindow()
{
super.onAttachedToWindow();
this.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
public void setColor(int color)
{
this.mColor = color;
}
public void setSpeed(int speed)
{
this.speed = speed;
}
public void setMinRadius(int radius)
{
this.minRadius = radius;
}
}
调用的代码:
[java] view
plaincopy
![](https://code.csdn.net/assets/CODE_ico.png)
package com.example.animdemo1;
import android.app.Activity;
import android.os.Bundle;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import com.example.view.RadiationView;
public class MainActivity extends Activity
{
private ImageView iv = null;
private RadiationView rv = null;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
iv = (ImageView) findViewById(R.id.iv_rotate);
rv = (RadiationView) findViewById(R.id.rv);
rv.setMinRadius(70);//辐射半径
rv.startRadiate();//开始辐射
Animation anim = AnimationUtils.loadAnimation(this, R.anim.rotate_circle_anim);
iv.startAnimation(anim);//开始动画
}
}
相关文章推荐
- 知乎首页 粒子效果 动态背景
- 动态调用仿腾讯拍拍首页的js广告效果特酷 推荐
- Android实现仿网易首页选项卡动态滑动效果
- 【jQuery小实例】---3 凤凰网首页图片动态效果
- 【jQuery小实例】---3 凤凰网首页图片动态效果
- 【安卓笔记】仿乐安全首页动态效果
- ScrollView实现图片拉伸效果,仿QQ好友动态头部效果
- Bootstrap Paginator分页插件与ajax相结合实现动态无刷新分页效果
- FCPX插件 Pixel Film Studios – PROLMK 动态图形遮罩效果 for Mac v1.0最新破解版
- 窗口动态效果 AnimateWindow 使用注意。
- android UI效果四: 动态填充Bitmap像素信息
- canvas绘图动态效果
- TabLayout+ViewPager实现选项卡动态滑动效果
- 删除后动态效果
- js+css绘制颜色动态变化的圈中圈效果
- 自定义ListView实现中间项动态变大的效果(不是自定义Adapter)
- iOS实现动态元素的引导图效果
- 首页飘雪的效果
- 关于动态加载的数据实现单选可取消的效果 并且附带 ScrollView滑动到指定位置
- 首页图片滚动效果