編輯:關於Android編程
第一個動畫文件btn_anim.xml
2-在res文件夾 anim文件夾下面,建立第二個文件layout_anim.xml):
3主activity 我是在fragment中使用,你就隨意吧。
...
private ScrollView scrollView; // This is my container. Yours may be different
private Animation btnAnim;
private Animation layoutAnim;
...
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// Getting context
context = getActivity().getApplicationContext();
btnAnim = AnimationUtils.loadAnimation(context, R.anim.btn_anim);
btnAnim.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
layoutAnim = AnimationUtils.loadAnimation(context, R.anim.layout_anim);
scrollView.startAnimation(layoutAnim);
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
// create view
View view = inflater.inflate(R.layout.fragment_browse_single, container, false);
scrollView = (ScrollView) view.findViewById(R.id.scrollView);
myButton = (Button) view.findViewById(R.id.myButton);
myButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
btnZan.startAnimation(btnAnim);
}
});
Log.i(TAG, "View created");
return view;
}

另一種demo做法。試用了線程。不推薦使用
publicclassapplaudAnimationextendsActivityimplementsOnClickListener {privateButton button;privateTextView textView;privateandroid.view.animation.Animation animation;publicvoidonCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.animation);animation = AnimationUtils.loadAnimation(this,R.anim.applaud_animation);button = (Button) findViewById(R.id.bt);button.setOnClickListener(this);textView = (TextView) findViewById(R.id.animation);}@OverridepublicvoidonClick(View v) {if(v == button) {textView.setVisibility(View.VISIBLE);textView.startAnimation(animation);newHandler().postDelayed(newRunnable() {publicvoidrun() {textView.setVisibility(View.GONE);}},1000);}}}animation.xml
"1.0"encoding="utf-8"?>"http://schemas.android.com/apk/res/android"android:layout_width="fill_parent"android:layout_height="fill_parent"android:background="#ffffff">
applaud_animation.xml"1.0"encoding="utf-8"?>"http://schemas.android.com/apk/res/android">android:fromXDelta="0"android:toXDelta="0"android:fromYDelta="0"android:toYDelta="-50"android:duration="1000"/>android:fromAlpha="1.0"android:toAlpha="0.3"android:duration="1000"/>
Android專用Log開源項目——KLog
在Android開發和調試的過程中,Log的使用是非常頻繁的,一個好的Log工具可以幫你節省很多時間,所以凱子哥抽空寫了個這個開源項目KLog,希望可以幫助大家提高開發
Android開發Tips
介紹一些, 在Android開發中, 會經常使用的小知識點.1. Download文件夾絕對路徑/storage/emulated/0/Download/xxx遍歷
android應用開發之spinner控件的簡單使用
Android的控件有很多種,其中就有一個Spinner的控件,這個控件其實就是一個下拉顯示列表。Spinner是位於 android.widget包下的,每
詳解Android中Handler的內部實現原理
本文主要是對Handler和消息循環的實現原理進行源碼分析,如果不熟悉Handler可以參見博文《詳解Android中Handler的使用方法》,裡面對Android為何