android组合动画还原,Android - Fragment,View动画,组合动画,属性动画
轉載請注明出處:https://blog.csdn.net/mythmayor/article/details/72876871
1.什么是Fragment
片段,碎片
* 從Android 3.0 (API level 11)開始引入Fragment的。
* Fragment包含在Activity中,Fragment只能存在于Activity的上下文(context)內,沒有Activity就無法使用Fragment,因此Fragment只能在Activity的上下文(context)創建。Fragment可以作為Activity的一部分,Fragment和Activity非常相似,Fragment擁有一個與Activity相關的視圖層次結構,擁有一個與Activity非常相似的生命周期。
2.為什么要使用Fragment
Activity的使用局限:不能將多個Activity界面放在屏幕上一并顯示。因此創建了Fragment來彌補Activity的局限。Fragment可以像Activity一樣響應Back鍵等類似Activity的功能。
3.創建Fragment
public class SoundFragment extends Fragment {
//返回當前fragment顯示的內容
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.sound, null);
}
}
4.展示一個Fragment到界面上
public void showSound(View view){
//創建Fragment
SoundFragment fragment = new SoundFragment();
//獲取Fragment管理器
FragmentManager fm = getFragmentManager();
//開啟事務
FragmentTransaction ft = fm.beginTransaction();
//將界面上的一塊布局替換為Fragment
ft.replace(R.id.container, fragment);
//提交事物
ft.commit();
}
5.Fragment事物的特點
fm.beginTransaction()和ft.commit()要配對使用
6.Fragment和Activity的通信
Fragment獲取Activity中的數據 //通過getActivity()獲取到所在Activity的引用,然后就可以拿到Activity里面的內容了
EditText et_name = (EditText) getActivity().findViewById(R.id.et_name);
Toast.makeText(getActivity(), "name:"+et_name.getText().toString(), 0).show();
Activity中獲取Fragment中的數據
Activity在創建Fragment時可以得到他的引用,利用引用就可以獲取里面的內容
創建Fragment時還可以使用replace的另一個方法,給Fragment設置一個tag,以后可以通過tag再次獲取這個Fragment fragmentTransaction.replace(int containerViewId, Fragment fragment, String tag);
fragmentManager.findFragmentByTag(String tag);
7.Fragment的生命周期
與Activity類似,在onCreateView()方法返回該Fragment的View
8.在兼容低版本的開發中如何使用Fragment
Activity要繼承FragmentActivity
使用getSupportFragmentManager()方法拿到FragmentManager
使用android.support.v4.app.Fragment下的Fragment
9.View動畫
透明度漸變動畫 AlphaAnimation aa = new AlphaAnimation(0.0f, 1.0f);
//動畫播放的時間長度
aa.setDuration(2000);
//設置重復播放的次數
aa.setRepeatCount(Animation.INFINITE);
//設置重復播放的模式
aa.setRepeatMode(Animation.REVERSE);
//讓iv播放aa動畫
iv.startAnimation(aa);
平移動畫 //Animation.RELATIVE_TO_SELF 相對于自己,值要填百分比
//Animation.RELATIVE_TO_PARENT 相對于父控件,值要填百分比
//Animation.ABSOLUTE 絕對坐標,值要填具體值
TranslateAnimation ta = new TranslateAnimation(
Animation.RELATIVE_TO_SELF, //起始x類型
0, //起始x值
Animation.RELATIVE_TO_SELF, //結束x類型
1f, //結束x值
Animation.RELATIVE_TO_SELF, //起始y類型
0, //起始y值
Animation.RELATIVE_TO_SELF, //結束y類型
1f); //結束y值
//動畫播放的時間長度
ta.setDuration(2000);
//設置重復播放的次數
ta.setRepeatCount(Animation.INFINITE);
//設置重復播放的模式
ta.setRepeatMode(Animation.REVERSE);
//讓iv播放aa動畫
iv.startAnimation(ta);
縮放動畫 ScaleAnimation sa = new ScaleAnimation(
0.2f, //x軸起始縮放比
2.0f, //x軸結束縮放比
0.2f, //y軸起始縮放比
2.0f, //y軸結束縮放比
Animation.RELATIVE_TO_SELF, //中心點x類型
0.5f, //中心點x值
Animation.RELATIVE_TO_SELF, //中心點y類型
0.5f //中心點y值
);
//動畫播放的時間長度
sa.setDuration(2000);
//設置重復播放的次數
sa.setRepeatCount(Animation.INFINITE);
//設置重復播放的模式
sa.setRepeatMode(Animation.REVERSE);
//讓iv播放aa動畫
iv.startAnimation(sa);
旋轉動畫 RotateAnimation ra = new RotateAnimation(
0,
360,
Animation.RELATIVE_TO_SELF,
0.5f,
Animation.RELATIVE_TO_SELF,
0.5f);
//動畫播放的時間長度
ra.setDuration(2000);
//設置重復播放的次數
ra.setRepeatCount(Animation.INFINITE);
//設置重復播放的模式
ra.setRepeatMode(Animation.REVERSE);
//讓iv播放aa動畫
iv.startAnimation(ra);
10.組合動畫的使用方式
AnimationSet set = new AnimationSet(false);
...
set.addAnimation(ta);
set.addAnimation(sa);
set.addAnimation(ra);
iv.startAnimation(set);
11.使用xml文件描述動畫
xml文件放在res/anim文件夾下
使用方式
Animation aa = AnimationUtils.loadAnimation(this, R.anim.alpha_demo);
iv.startAnimation(aa);
12.View動畫的特點
View的位置并沒有真正的變化,只是改變了渲染的位置
13.屬性
生成了get、set方法的成員變量就稱為屬性
14.屬性動畫的使用方式
ObjectAnimator oa = ObjectAnimator.ofFloat(iv, "translationY", new float[]{0,2,4,6,8,10,15,20,25,30,50,80,100,150});
oa.setDuration(2000);
oa.setRepeatCount(ObjectAnimator.INFINITE);
oa.setRepeatMode(ObjectAnimator.RESTART);
oa.start();
15.屬性動畫的特點
View的位置真正的發生了變化
16.屬性動畫集合的使用方式
AnimatorSet set = new AnimatorSet();
//順序播放
set.playSequentially(oa,oa2);
//同時播放
set.playTogether(oa,oa2);
17.使用xml文件描述屬性動畫
xml文件放在res/animator文件夾下
使用方式
Animator animator = AnimatorInflater.loadAnimator(this, R.animator.alpha);
animator.setTarget(iv);
animator.start();
18.總結
Fragment
什么是Fragment
Fragment的顯示
Fragment與Activity的通信
Fragment的生命周期
不同版本中如何使用Fragment
View動畫
平移、縮放、旋轉、透明度漸變動畫
組合動畫
xml文件定義動畫
屬性(Property)動畫
屬性動畫的使用
屬性動畫的組合播放
xml文件定義屬性動畫
View動畫和屬性動畫的區別
應用程序的反編譯
總結
以上是生活随笔為你收集整理的android组合动画还原,Android - Fragment,View动画,组合动画,属性动画的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: android点击事件的优先级,andr
- 下一篇: android调频收音机代码,andro