編輯:關於Android編程
animationSet.setRepeatCount(2);
下面是例子程序
activity_main.xml
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
MainActivity.java
package com.yx.animations01;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.view.animation.TranslateAnimation;
import android.widget.Button;
import android.widget.ImageView;
public class MainActivity extends Activity {
private Button scaleButton=null;
private Button rotateButton=null;
private Button alphaButton=null;
private Button translateButton=null;
private ImageView imageView = null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scaleButton = (Button) findViewById(R.id.scaleButton);
scaleButton.setOnClickListener(new scaleButtonListener());
rotateButton = (Button) findViewById(R.id.rotateButton);
rotateButton.setOnClickListener(new rotateButtonListener());
alphaButton = (Button) findViewById(R.id.alphaButton);
alphaButton.setOnClickListener(new alphaButtonListener());
translateButton = (Button) findViewById(R.id.translateButton);
translateButton.setOnClickListener(new translateButtonListener());
imageView = (ImageView) findViewById(R.id.imageViewId);
}
class scaleButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// 創建一個AnimationSet對象
AnimationSet animationSet = new AnimationSet(true);
/*Parameters
fromX Horizontal scaling factor to apply at the start of the animation
toX Horizontal scaling factor to apply at the end of the animation
fromY Vertical scaling factor to apply at the start of the animation
toY Vertical scaling factor to apply at the end of the animation
pivotXType Specifies how pivotXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
pivotXValue The X coordinate of the point about which the object is being scaled, specified as an absolute number where 0 is the left edge. (This point remains fixed while the object changes size.) This value can either be an absolute number if pivotXType
is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
pivotYType Specifies how pivotYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
pivotYValue The Y coordinate of the point about which the object is being scaled, specified as an absolute number where 0 is the top edge. (This point remains fixed while the object changes size.) This value can either be an absolute number if pivotYType is
ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
*/
ScaleAnimation scaleAnimation = new ScaleAnimation(1,0.1f,1,0.1f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0.5f
);
//設置動畫執行的時間為1s
scaleAnimation.setDuration(1000);
//將alphaAnimation添加到animationSet中
animationSet.addAnimation(scaleAnimation);
//imageView的setAnimation(animationSet)執行動畫
imageView.setAnimation(animationSet);
}
}
class rotateButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// 創建一個AnimationSet對象
AnimationSet animationSet = new AnimationSet(true);
/**
* Parameters
fromDegrees Rotation offset to apply at the start of the animation.
toDegrees Rotation offset to apply at the end of the animation.
pivotXType Specifies how pivotXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
pivotXValue The X coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the left edge. This value can either be an absolute number if pivotXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
pivotYType Specifies how pivotYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
pivotYValue The Y coordinate of the point about which the object is being rotated, specified as an absolute number where 0 is the top edge. This value can either be an absolute number if pivotYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
*/
//1.從哪個角度2.到那個角度3.x軸坐標的類型可取值Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT
//4.其中1f表示一個父控件的橫坐標5-6同3-4
RotateAnimation rotateAnimation = new RotateAnimation(0,360,
Animation.RELATIVE_TO_PARENT,1f,
Animation.RELATIVE_TO_PARENT,0f
);
rotateAnimation.setDuration(1000);
animationSet.addAnimation(rotateAnimation);
//imageView的setAnimation(animationSet)執行動畫
imageView.setAnimation(animationSet);
}
}
//淡入淡出
class alphaButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// 創建一個AnimationSet對象
AnimationSet animationSet = new AnimationSet(true);
//創建一個AlphaAnimation對象括號為從什麼透明度到什麼樣的透明度1為不透明,0為透明
AlphaAnimation alphaAnimation = new AlphaAnimation(1,0);
//設置動畫執行的時間為1s
alphaAnimation.setDuration(1000);
//將alphaAnimation添加到animationSet中
animationSet.addAnimation(alphaAnimation);
//imageView的setAnimation(animationSet)執行動畫
imageView.setAnimation(animationSet);
}
}
class translateButtonListener implements OnClickListener{
@Override
public void onClick(View v) {
// 創建一個AnimationSet對象
AnimationSet animationSet = new AnimationSet(true);
/*
* Parameters
fromXType Specifies how fromXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
fromXValue Change in X coordinate to apply at the start of the animation. This value can either be an absolute number if fromXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
toXType Specifies how toXValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
toXValue Change in X coordinate to apply at the end of the animation. This value can either be an absolute number if toXType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
fromYType Specifies how fromYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
fromYValue Change in Y coordinate to apply at the start of the animation. This value can either be an absolute number if fromYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
toYType Specifies how toYValue should be interpreted. One of Animation.ABSOLUTE, Animation.RELATIVE_TO_SELF, or Animation.RELATIVE_TO_PARENT.
toYValue Change in Y coordinate to apply at the end of the animation. This value can either be an absolute number if toYType is ABSOLUTE, or a percentage (where 1.0 is 100%) otherwise.
*/
TranslateAnimation translateAnimation = new TranslateAnimation(
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF,0.5f,
Animation.RELATIVE_TO_SELF,0f,
Animation.RELATIVE_TO_SELF,1.0f
);
//設置動畫執行的時間為1s
animationSet.setDuration(1000);
animationSet.setFillAfter(true);
animationSet.setFillBefore(false);
animationSet.setStartOffset(1000);
animationSet.setRepeatCount(2);
//將alphaAnimation添加到animationSet中
animationSet.addAnimation(translateAnimation);
//imageView的setAnimation(animationSet)執行動畫
imageView.setAnimation(animationSet);
}
}
}
現在很多app都用到了頭像的功能,我的項目中也用到了。頭像上傳分幾步:1.獲取頭像2.剪裁頭像3.文件上傳4.服務器的接受保存首先第一步,無非就是兩種方式1,拍照2,相冊
把自定義表格又改進了一下,可以支持行合並。表格分為簡單和復雜兩種模式 1、簡單模式就是《Android中使用ListView繪制自定義表格(2)》描述的方式。不支持行合並
概述http Cache指的是web浏覽器所具有的復用本地已緩存的文檔”副本”的能力。我們知道,通過網絡獲取內容有時候成本很高,因而緩
需求:想讓用戶掃描一個二維碼就能下載APP,並統計被掃描次數。兩種實現方法:1.一般我們用草料生成二維碼,如果沒有注冊的話只能生成一個包含下載網址的靜態碼,沒有統計功能,