当前位置:首页 » 安卓系统 » interpolatorandroid

interpolatorandroid

发布时间: 2022-04-23 06:45:27

Ⅰ android 是怎么通过在XML中配置的控件属性得到具体的view对象

我可能表达的不是很清楚,那就拿个具体的例子来说明吧
比如说,在Activity中我们需要用到一个ProgressBar控件,我们一般先在layout下的main.xml中进行配置
Xml代码
<ProgressBar
android:id="@+id/pb1"
android:layout_width="fill_parent"
android:layout_height="20dip"
<span style="color: #ff0000;"> android:indeterminateOnly="false"</span>

android:layout_gravity="center_vertical"
android:progressDrawable="@android:drawable/progress_horizontal"
android:indeterminateDrawable="@android:drawable/progress_indeterminate_horizontal"
android:minHeight="20dip"
android:maxHeight="20dip"
/>

我们看 android:indeterminateOnly="false" 这行代码的
一般我们如果要将在代码中创建一个ProgressBar,但是不通过配置文件得到。
代码如下:
java代码
ProgressBar mProgressBar=new ProgressBar(context);

<span style="color: #ff0000;">mProgressBar.setIndeterminate(false); </span>

mProgressBar.setProgressDrawable(getResources().getDrawable
(android.R.drawable.progress_horizontal));

mProgressBar.setIndeterminateDrawable(getResources().getDrawable
(android.R.drawable.progress_indeterminate_horizontal));

本来我们是希望创建一个普通的能显示进度的横条ProgressBar
但是我们发现progressBar中的进度无法更新。
我们来看进度更新的源代码setProgress():
Java代码
@android.view.RemotableViewMethod
synchronized void setProgress(int progress, boolean fromUser) {
<span style="color: #ff0000;"> if (mIndeterminate) {
return;
}</span>

if (progress < 0) {
progress = 0;
}
if (progress > mMax) {
progress = mMax;
}
if (progress != mProgress) {
mProgress = progress;
refreshProgress(R.id.progress, mProgress, fromUser);
}
}

关键是: if (mIndeterminate) { return; }
原来mIndeterminate 的值为true的话,函数直接返回了,也就是我们不能设置progressBar的进度(mProgress)
现在我们的任务是将mIndeterminate 属性设置为false
但是我们发现 mProgressBar.setIndeterminate(false); 这行代码并没有设置mIndeterminate 属性为false
我们看ProgressBar中的源代码:

Java代码
@android.view.RemotableViewMethod
public synchronized void setIndeterminate(boolean indeterminate) {
<span style="color: #ff0000;"> if ((!mOnlyIndeterminate || !mIndeterminate) && indeterminate != mIndeterminate) {</span>

mIndeterminate = indeterminate;

if (indeterminate) {
// swap between indeterminate and regular backgrounds
mCurrentDrawable = mIndeterminateDrawable;
startAnimation();
} else {
mCurrentDrawable = mProgressDrawable;
stopAnimation();
}
}
}

看这行代码: if ((!mOnlyIndeterminate || !mIndeterminate) && indeterminate != mIndeterminate) {
我们发现当mOnlyIndeterminate 和mIndeterminate 之前都为true时,我们并不能将mIndeterminate 从true改变为false

google后,有人通过反射机制将ProgressBar中的mOnlyIndeterminate 设置为false(具体请看:关于使用代码来创建ProgressBar )

我现在我就在想 既然 ProgressBar中的mOnlyIndeterminate 和mIndeterminate属性都是private,而且都不能通过get和set方法来对其进行操作,那么 android 通过在XML中配置的控件属性,是怎么被转换成真正的java类呢?

求大神解惑!

问题补充

over140 写道
你应该看一下他源码里关于这个的构造函数部分的代码,注意父类里面可能也有代码,他并不是转换成java类,只是读取从XML属性读取想要的参数。

你指的是ProgressBar类中的构造函数吗? 我之前就仔细看了这些东西
ProgressBar中构造函数源码:
Java代码
/**
* Create a new progress bar with range 0...100 and initial progress of 0.
* @param context the application environment
*/
public ProgressBar(Context context) {
this(context, null);
}

public ProgressBar(Context context, AttributeSet attrs) {
this(context, attrs, com.android.internal.R.attr.progressBarStyle);
}

public ProgressBar(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
mUiThreadId = Thread.currentThread().getId();
initProgressBar();

TypedArray a =
context.obtainStyledAttributes(attrs, R.styleable.ProgressBar, defStyle, 0);

mNoInvalidate = true;

Drawable drawable = a.getDrawable(R.styleable.ProgressBar_progressDrawable);
if (drawable != null) {
drawable = tileify(drawable, false);
setProgressDrawable(drawable);
}

mDuration = a.getInt(R.styleable.ProgressBar_indeterminateDuration, mDuration);

mMinWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_minWidth, mMinWidth);
mMaxWidth = a.getDimensionPixelSize(R.styleable.ProgressBar_maxWidth, mMaxWidth);
mMinHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_minHeight, mMinHeight);
mMaxHeight = a.getDimensionPixelSize(R.styleable.ProgressBar_maxHeight, mMaxHeight);

mBehavior = a.getInt(R.styleable.ProgressBar_indeterminateBehavior, mBehavior);

final int resID = a.getResourceId(
com.android.internal.R.styleable.ProgressBar_interpolator,
android.R.anim.linear_interpolator); // default to linear interpolator
if (resID > 0) {
setInterpolator(context, resID);
}

setMax(a.getInt(R.styleable.ProgressBar_max, mMax));

setProgress(a.getInt(R.styleable.ProgressBar_progress, mProgress));

setSecondaryProgress(
a.getInt(R.styleable.ProgressBar_secondaryProgress, mSecondaryProgress));

drawable = a.getDrawable(R.styleable.ProgressBar_indeterminateDrawable);
if (drawable != null) {
drawable = tileifyIndeterminate(drawable);
setIndeterminateDrawable(drawable);
}

mOnlyIndeterminate = a.getBoolean(
R.styleable.ProgressBar_indeterminateOnly, mOnlyIndeterminate);

mNoInvalidate = false;

setIndeterminate(mOnlyIndeterminate || a.getBoolean(
R.styleable.ProgressBar_indeterminate, mIndeterminate));

a.recycle();
}

看以上代码,发现ProgressBar类并没有使用其父类的构造方法, 它的三个构造方法最终都需要进入到第三个构造方法内,
再看这一句
Java代码
initProgressBar();

其中具体源码如下:
Java代码
private void initProgressBar() {
mMax = 100;
mProgress = 0;
mSecondaryProgress = 0;
mIndeterminate = false;
mOnlyIndeterminate = false;
mDuration = 4000;
mBehavior = AlphaAnimation.RESTART;
mMinWidth = 24;
mMaxWidth = 48;
mMinHeight = 24;
mMaxHeight = 48;
}

看 这两句:
Java代码
mIndeterminate = false;
mOnlyIndeterminate = false;

奇怪 在这个初始化ProgressBar的过程中,明明将mIndeterminate和mOnlyIndeterminate属性设置为false
但是我们初始化后的进度条,显示后同样是不会进度的(图如下)

也就是说 mIndeterminate属性依然是true(具体请看ProgressBar中的setProgress()方法)

继续看构造方法中的其他内容时,发现关键所在:
Java代码
mOnlyIndeterminate = a.getBoolean(
R.styleable.ProgressBar_indeterminateOnly, mOnlyIndeterminate);

mNoInvalidate = false;

setIndeterminate(mOnlyIndeterminate || a.getBoolean(
R.styleable.ProgressBar_indeterminate, mIndeterminate));

这两句将mOnlydeterminate和mIndeterminate属性都设置为true,
看到这里,发现这两句都用到 a 这个对象,a 具体是什么呢?

Java代码
TypedArray a =
context.obtainStyledAttributes(attrs, R.styleable.ProgressBar, defStyle, 0);

那我们能不能通过改变传入 构造函数 的参数 来使 a 发生相应的变化,进而使mOnlyIndeterminate和mIndeterminate属性设置为 true 呢?
再往下深入,发现看的我那是一头雾水,完全找不到方向,所以只得放弃这个猜想。

到最后,我发现 如果要通过正常的java访问机制(当然排除使用反射机制),来操作mOnlyIndeterminate和mIndeterminate属性是不可能的,

你说: 他并不是转换成java类,只是读取从XML属性读取想要的参数。

我们一般是通过findViewById()来根据layout中的XML文件设置的控件属性得到 具体的View控件对象(关于转换成java类,我错了,其实我想说的是怎么得到的这个对象),
这个过程是不是也是通过反射机制来完成的?假如是的话,能给我提供些具体过程的资料呢?

Ⅱ android 如何让控件慢慢展开

Android为了用户获得更好的体验,引入了动画的概念,有逐祯的方式,所以为了让控件展开,可以利用Anima这个类提供的方法,可以参考这位前辈的方式,代码如下:

注释已经很清楚了,在普及以下android动画的概念:

Tween Animation有四种形式:

1.渐变透明度动画效果。

2.渐变尺寸伸缩动画效果。

3.画面位置移动动画效果。

4.画面旋转动画效果。

这四种动画实现方式都是通过Animation类和AnimationUtils配合实现。

可以通过xml实现:动画的XML文件在工程中res/anim目录。还有一种就是我上面所说的逐祯动画了,具体的用法可以再网络一下,有很多资料可以参考。

Ⅲ android中怎么定义旋转动画的旋转速度

android源代码之Rotate旋转动画
标签为旋转节点
Tween一共为我们提供了3种动画渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 设置动画渲染器为加速动画(动画播放中越来越快)
android:interpolator="@android:anim/decelerate_interpolator" 设置动画渲染器为减速动画(动画播放中越来越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 设置动画渲染器为先加速在减速(开始速度最快 逐渐减慢)
如果不写的话 默认为匀速运动
android:fromDegrees="+360"设置动画开始的角度
android:toDegrees="0"设置动画结束的角度
这个动画布局设置动画将向左做360度旋转加速运动。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
复制代码
代码实现
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋转动画按钮**/
Button mButton0 = null;
/**向右旋转动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**向左旋转动画**/
Animation mLeftAnimation = null;
/**向右旋转动画**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载向左与向右旋转动画**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋转动画**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋转动画**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}

Ⅳ 如何实现Rotate旋转动画的android源代码

android源代码之Rotate旋转动画
标签为旋转节点
Tween一共为我们提供了3种动画渲染模式。
android:interpolator="@android:anim/accelerate_interpolator" 设置动画渲染器为加速动画(动画播放中越来越快)
android:interpolator="@android:anim/decelerate_interpolator" 设置动画渲染器为减速动画(动画播放中越来越慢)
android:interpolator="@android:anim/accelerate_decelerate_interpolator" 设置动画渲染器为先加速在减速(开始速度最快 逐渐减慢)
如果不写的话 默认为匀速运动
android:fromDegrees="+360"设置动画开始的角度
android:toDegrees="0"设置动画结束的角度
这个动画布局设置动画将向左做360度旋转加速运动。
android:interpolator="@android:anim/accelerate_interpolator"
android:fromDegrees="+360"
android:toDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:ration="2000"
/>
复制代码
代码实现
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
public class RotateActivity extends Activity {
/**向左旋转动画按钮**/
Button mButton0 = null;
/**向右旋转动画按钮**/
Button mButton1 = null;
/**显示动画的ImageView**/
ImageView mImageView = null;
/**向左旋转动画**/
Animation mLeftAnimation = null;
/**向右旋转动画**/
Animation mRightAnimation = null;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.retate);
/**拿到ImageView对象**/
mImageView = (ImageView)findViewById(R.id.imageView);
/**加载向左与向右旋转动画**/
mLeftAnimation = AnimationUtils.loadAnimation(this, R.anim.retateleft);
mRightAnimation = AnimationUtils.loadAnimation(this, R.anim.retateright);
mButton0 = (Button)findViewById(R.id.button0);
mButton0.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向左旋转动画**/
mImageView.startAnimation(mLeftAnimation);
}
});
mButton1 = (Button)findViewById(R.id.button1);
mButton1.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
/**播放向右旋转动画**/
mImageView.startAnimation(mRightAnimation);
}
});
}
}
学习更多关于android源代码,可以查询

Ⅳ 请教高手,android 页面跳转 屏幕向左或者向右移动出现 ,急、急。。。谢谢了。

在跳转到页面前的startActivity()方法后调用
overridePendingTransition(R.anim.activity_open_enter, 0);方法
在返回页面前的finish()方法后调用
overridePendingTransition(0, R.anim.activity_close_exit);方法
就可以了
其中activity_open_enter内容为:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@anim/decelerate_interpolator">
<translate android:fromXDelta="33%" android:toXDelta="0"
android:ration="@android:integer/config_shortAnimTime"/>
</set>
activity_close_exit内容为:
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@anim/decelerate_interpolator">
<translate android:fromXDelta="0%" android:toXDelta="33%"
android:ration="@android:integer/config_shortAnimTime"/>
</set>
不过要注意overridePendingTransition是API Level5中的方法,也就是说2。01之前的sdk中都不可用

Ⅵ 安卓编程 如何实现点击才滑动

intent.setClass(First.this,Second.class);
startActivity(intent);
// 添加Activity间的跳转动画
overridePendingTransition(R.anim.anim_in, R.anim.anim_out);

anim.anim_in.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
Android:interpolator="@android:anim/decelerate_interpolator" >

<scale
Android:ration="2000"
Android:fromXScale="2.0"
Android:fromYScale="2.0"
Android:pivotX="50%"
Android:pivotY="50%"
Android:toXScale="1.0"
Android:toYScale="1.0" />

</set>
anim.anim_out.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:Android="http://schemas.android.com/apk/res/android"
Android:interpolator="@android:anim/decelerate_interpolator"
Android:zAdjustment="top" >

<scale
Android:ration="2000"
Android:fromXScale="0.5"
Android:fromYScale="0.5"
Android:pivotX="50%p"
Android:pivotY="50%p"
Android:toXScale="2.0"
Android:toYScale="2.0" />

<alpha
Android:ration="2000"
Android:fromAlpha="1.0"
Android:toAlpha="0" />

</set>

代码不会给你,长不长的不说,主要是不让给。思路其实很简单,就是响应屏幕触点事件,判断触点区域,切换界面图片。最简单的实现:6张图,分别是一张触摸图(就是你图中那个黄边的锁),一张区域整体透明图,四张上下左右响应变化整体图,然后根据触摸的位置切换图片就行了。(其中还是有些小麻烦和小技巧,你自己试试就知道了,不难解决)。

Ⅶ 如何设定Android Activity间切换时的动画

转载本代码示例介绍如何设定Activity间切换时的动画效果。本示例使用Eclipse的Android工程编译测试。

1. 定义清单文件(AndroidManifest.xml)

<?xml version="1.0" encoding="utf-8"?>

<manifest xmlns:android="http。//schemas。android。com/apk/res/android"

package="my.android.test"

android:versionCode="1"

android:versionName="1.0">

<application android:icon="@drawable/icon" android:label="@string/app_name">

<activity android:name=".Animation"

android:label="@string/app_name">

<intent-filter>

<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />

</intent-filter>

</activity>

<activity android:name=".Controls1"

android:label="@string/app_name"

android:theme="@android:style/Theme.Light">

</activity>

</application>

<uses-sdk android:minSdkVersion="9" />

</manifest>

2. 定义字符串资源(res/values/strings.xml)

<?xml version="1.0" encoding="utf-8"?>

<resources>

<string name="hello">Hello World,Aniation!</string>

<string name="app_name">Animation</string>

<string name="activity_animation_msg">Press a button to launch an activity with a custom animation.</string>

<string name="activity_animation_fade">Fade in</string>

<string name="activity_animation_zoom">Zoom in</string>

<string name="controls_1_save">Save</string>

<string name="controls_1_checkbox_1">Checkbox 1</string>

<string name="controls_1_checkbox_2">Checkbox 2</string>

<string name="controls_1_radiobutton_1">RadioButton 1</string>

<string name="controls_1_radiobutton_2">RadioButton 2</string>

<string name="controls_1_star">Star</string>

<string name="textColorPrimary">textColorPrimary</string>

<string name="textColorSecondary">textColorSecondary</string>

<string name="textColorTertiary">textColorTertiary</string>

<string name="listSeparatorTextViewStyle">listSeparatorTextViewStyle</string>

</resources>

3. 定义渐入动画资源定义(res/anim/fade.xml、res/anim/hold.xml)

res/anim/fade.xml文件

<?xml version="1.0" encoding="utf-8"?>

<!-- 声明动画对象的透明度,本例使用渐入的方式,显示Activity

属性说明参照zoom_exit.xml -->

<alpha xmlns:android="http。//schemas。android。com/apk/res/android"

android:interpolator="@android:anim/accelerate_interpolator"

android:fromAlpha="0.0" android:toAlpha="1.0"

android:ration="@android:integer/config_longAnimTime" />

res/anim/hold.xml文件

<?xml version="1.0" encoding="utf-8"?>

<!-- 声明动画对象的水平和垂直移动量,本例使用水平移动方式,

android:interpolator:指定在设定时间内动画移动过程中插补器,用于改善动画的平滑度

android:fromXDelta:指定动画开始时,动画对象的水平位置,可以用像素智设定,也可以用

相对父窗口宽度的百分比来设定。

android:toXDelta:指定动画结束时,动画对象的水平位置,可以用像素值来设定,也可以用

相对父窗口宽度的百分比来设定。

android:ration:指定动画的播放时间

-->

<translate xmlns:android="http。//schemas。android。com/apk/res/android"

android:interpolator="@android:anim/accelerate_interpolator"

android:fromXDelta="0" android:toXDelta="0"

android:ration="@android:integer/config_longAnimTime" />

4. 定义缩放动画资源定义(res/anim/zoom_enter.xml、res/anim/zoom_exit.xml)

res/anim/zoom_enter.xml文件

<?xml version="1.0" encoding="utf-8"?>

<!-- 声明动画对象进入屏幕时的动画资源

android:interpolator:指定在设定时间内动画移动过程中插补器,用于改善动画的平滑度

-->

<set xmlns:android="http。//schemas。android。com/apk/res/android"

android:interpolator="@android:anim/decelerate_interpolator">

<!-- 声明动画对象进入屏幕时的缩放动画,

属性说明参照zoom_exit.xml -->

<scale android:fromXScale="2.0" android:toXScale="1.0"

android:fromYScale="2.0" android:toYScale="1.0"

android:pivotX="50%p" android:pivotY="50%p"

android:ration="@android:integer/config_mediumAnimTime" />

</set>

res/anim/zoom_exit.xml文件

<?xml version="1.0" encoding="utf-8"?>

<!-- 声明Activity退出时使用的动画资源

android:interpolator:指定在设定时间内动画移动过程中插补器,用于改善动画的平滑度

android:zAdjustment:允许再动画播放期间,调整播放内容在Z轴方向的顺序,normal(0):真正播放的

动画内容保持当前的Z轴顺序,top(1):在动画播放期间,强制把当前播放的内容放到其他内容的上面;

bottom(-1):在动画播放期间,强制把当前播放的内容放到其他内容之下。

-->

<set xmlns:android="http。//schemas。android。com/apk/res/android"

android:interpolator="@android:anim/decelerate_interpolator"

android:zAdjustment="top">

<!-- 指定动画对象的缩放因子和播放时间

android:fromXScale和android:toXScale指定X轴的动画开始和结束时的缩放因子

android:fromYScale和android:toYScale指定Y轴的动画开始和结束时的缩放因子

android:pivoteX:在动画对象被缩放时,X轴要保留的原始尺寸的百分比。

android:pivoteY:在动画对象被缩放时,Y轴要保留的原始尺寸的百分比。

android:ration指定动画的播放时间

-->

<scale android:fromXScale="1.0" android:toXScale=".5"

android:fromYScale="1.0" android:toYScale=".5"

android:pivotX="50%p" android:pivotY="50%p"

android:ration="@android:integer/config_mediumAnimTime" />

<!-- 定义动画对象的透明度,该动画在动画缩放之后播放。

android:fromAlpha:指定动画初始时的透明度

android:toAlpha:指定动画结束时的透明度

android:ratiion:指定动画透明处理的执行时间

-->

<alpha android:fromAlpha="1.0" android:toAlpha="0"

android:ration="@android:integer/config_mediumAnimTime"/>

</set>

Ⅷ android开发中如何旋转布局

楼主你好,这个可以通过动画来达到这个效果的,代码如下:
只要把您的layout对象传进去就行了
public void showAnimation(View mView)
{
final float centerX = mView.getWidth() / 2.0f;
final float centerY = mView.getHeight() / 2.0f;
//这个是设置需要旋转的角度,我设置的是180度
RotateAnimation rotateAnimation = new RotateAnimation(0, 180, centerX,
centerY);
//这个是设置通话时间的
rotateAnimation.setDuration(1000*3);
rotateAnimation.setFillAfter(true);
mView.startAnimation(rotateAnimation);
}

Ⅸ 安卓开发旋转动画实现的时候为什么会刷新界面

Android 平台提供了两类动画,一类是 Tween 动画,即通过对场景里的对象不断做图像变换(平移、缩放、旋转)产生动画效果;第二类是 Frame 动画,即顺序播放事先做好的图像,跟电影类似。本文分析 Tween动画的rotate实现旋转效果。 在新浪微博客户端中各个操作进行中时activity的右上角都会有个不停旋转的图标,类似刷新的效果,给用户以操作中的提示。这种非模态的提示方式推荐使用,那么下面就分享下如何实现这种效果吧 1、定义一个ImageView 定义一个ImageView是为了装载图片,其中的图片将被rotate用来进行旋转,其他View亦可。 资源文件为 Java代码 xmlns:android="schemas/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent"> android:id="@+id/infoOperating" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/operating" android:scaleType="center"> 其中的android:src为图片内容,可使用附件中的图片。 java代码为 Java代码 ImageView infoOperatingIV = (ImageView)findViewById(R.id.infoOperating); 2、定义rotate旋转效果 在res/anim文件夹下新建tip.xml文件,内容如下 Java代码 android:fromDegrees="0" android:toDegrees="359" android:ration="500" android:repeatCount="-1" android:pivotX="50%" android:pivotY="50%" /> 含义表示从0到359度开始循环旋转,0-359(若设置成360在停止时会出现停顿现象)度旋转所用时间为500ms,旋转中心距离view的左顶点为50%距离,距离view的上边缘为50%距离,即正中心,具体每个含义见下面的具体属性介绍。 java代码为 Java代码 Animation operatingAnim = AnimationUtils.loadAnimation(this, R.anim.tip); LinearInterpolator lin = new LinearInterpolator(); operatingAnim.setInterpolator(lin); setInterpolator表示设置旋转速率。LinearInterpolator为匀速效果,Accelerateinterpolator为加速效果、DecelerateInterpolator为减速效果,具体可见下面android:interpolator的介绍。 a. 关于其中的属性意义如下(红色部分加以注意): android:fromDegrees 起始的角度度数 android:toDegrees 结束的角度度数,负数表示逆时针,正数表示顺时针。如10圈则比android:fromDegrees大3600即可 android:pivotX 旋转中心的X坐标 浮点数或是百分比。浮点数表示相对于Object的左边缘,如5; 百分比表示相对于Object的左边缘,如5%; 另一种百分比表示相对于父容器的左边缘,如5%p; 一般设置为50%表示在Object中心 android:pivotY 旋转中心的Y坐标 浮点数或是百分比。浮点数表示相对于Object的上边缘,如5; 百分比表示相对于Object的上边缘,如5%; 另一种百分比表示相对于父容器的上边缘,如5%p; 一般设置为50%表示在Object中心 android:ration 表示从android:fromDegrees转动到android:toDegrees所花费的时间,单位为毫秒。可以用来计算速度。 android:interpolator表示变化率,但不是运行速度。一个插补属性,可以将动画效果设置为加速,减速,反复,反弹等。默认为开始和结束慢中间快, android:startOffset 在调用start函数之后等待开始运行的时间,单位为毫秒,若为10,表示10ms后开始运行 android:repeatCount 重复的次数,默认为0,必须是int,可以为-1表示不停止 android:repeatMode 重复的模式,默认为restart,即重头开始重新运行,可以为reverse即从结束开始向前重新运行。在android:repeatCount大于0或为infinite时生效 android:detachWallpaper 表示是否在壁纸上运行 android:zAdjustment 表示被animated的内容在运行时在z轴上的位置,默认为normal。 normal保持内容当前的z轴顺序 top运行时在最顶层显示 bottom运行时在最底层显示 b. 运行速度 运行速度为运行时间(android:ration)除以运行角度差(android:toDegrees-android:fromDegrees),比如android:ration为1000,android:toDegrees为360,android:fromDegrees为0就表示1秒转1圈。 c. 循环运行 Java代码 android:fromDegrees="0" android:toDegrees="360" android:repeatCount="-1" android:repeatCount="-1"即表示循环运行,配合上android:fromDegrees="0" android:toDegrees="360"表示不间断 3、开始和停止旋转 在操作开始之前调用 Java代码 if (operatingAnim != null) { infoOperatingIV.startAnimation(operatingAnim); } 在操作完成时调用 Java代码 infoOperatingIV.clearAnimation(); 许多朋友不知道如何停止旋转animation,所以强制设置rotate转动多少圈表示操作,但却无法与操作实际的进度匹配上,实际上只要如上代码所示清除animation即可。 其他: 对于上面的转动在横屏(被设置为了不重绘activity)时会出现问题,即旋转中心偏移,导致动画旋转偏离原旋转中心。解决如下 Java代码 @Override public void onConfigurationChanged(Configuration newConfig) { super.onConfigurationChanged(newConfig); if (operatingAnim != null && infoOperatingIV != null && operatingAnim.hasStarted()) { infoOperatingIV.clearAnimation(); infoOperatingIV.startAnimation(operatingAnim); } }

Ⅹ android 怎么实现沿控件方向做位移动画

在Android开发,我们会经常使用到位移动画,一般情况下位移动画有两种实现方式,一种是直接通过Java代码去实现,另外一种是通过配置文件实现动画,下面是两种动画的基本是使用方法:

纯Java代码实现:

[java] view plain
//创建渐变动画
Animation animation = new TranslateAnimation(0, 0, 300, 300);
animation.setDuration(1500);
animation.setRepeatCount(1);//动画的重复次数
animation.setFillAfter(true);//设置为true,动画转化结束后被应用
imageView1.startAnimation(animation);//开始动画

通过配置文件实现:
1、首先要在res目录下建立一个anim文件,在anim建立一个alpha1.xml文件如下:

[java] view plain
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:ration="1500"
android:fromXDelta="0"
android:fromYDelta="0"
android:toXDelta="200"
android:toYDelta="300"
android:repeatCount="3"
android:interpolator="@android:anim/cycle_interpolator"
android:repeatMode="reverse"
/>

</set>

2、加载动画

[java] view plain
Animation animation = AnimationUtils.loadAnimation(this, R.anim.translate);
imageView1.startAnimation(animation);//开始动画
案例下载地址:http://download.csdn.net/detail/u013043346/9374204

热点内容
安卓手机视频换脸软件哪个好 发布:2025-05-16 12:30:06 浏览:642
冒险房密码是什么 发布:2025-05-16 12:12:30 浏览:407
怎么查数据库服务器ip地址 发布:2025-05-16 12:11:54 浏览:369
python中文web 发布:2025-05-16 12:10:13 浏览:767
windowsandroid编译 发布:2025-05-16 12:02:23 浏览:333
为什么华为的系统是安卓 发布:2025-05-16 12:02:11 浏览:127
app怎么提供服务器地址 发布:2025-05-16 11:48:27 浏览:397
双面警长第一季ftp 发布:2025-05-16 11:41:20 浏览:664
php取数组第一个 发布:2025-05-16 11:30:58 浏览:423
解调算法 发布:2025-05-16 11:21:09 浏览:136