欢迎界面动画
實現一個歡迎界面的動畫,即打開app顯示的頁面,動畫結束后跳到Activity。
1、歡迎界面的背景是一個綠色矩形
<?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/android"android:shape="rectangle" ><solid android:color="#19cc54"/></shape>
2、歡迎界面的布局,整個布局的背景為上面的綠色矩形背景,此外包括兩個TextView
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:layout_width="match_parent"android:layout_height="match_parent"android:orientation="vertical"android:background="@drawable/bg_welcome"android:id="@+id/welcom_layout" ><TextViewandroid:id="@+id/welcomImage"android:layout_height="wrap_content"android:layout_width="wrap_content"android:layout_gravity="center"android:gravity="center"android:layout_marginLeft="20dp"android:layout_marginTop="200dp"android:text="@string/welcom"android:textSize="@dimen/welcomtext"android:textColor="@android:color/white"/> <!-- Welcom to Sunnys blog --><TextViewandroid:id="@+id/madeby"android:layout_height="wrap_content"android:layout_width="wrap_content"android:text="@string/made_by"android:layout_gravity="center"android:layout_marginLeft="80dp" android:layout_marginTop="150dp" android:textSize="@dimen/welcom_madeby"android:textColor="@android:color/white"/></LinearLayout>
3、歡迎界面的動畫
是逐漸縮小,淡出的效果,動畫持續4000毫秒
<?xml version="1.0" encoding="utf-8"?> <set xmlns:android="http://schemas.android.com/apk/res/android"android:duration="4000"><scaleandroid:fromXScale="1.0"android:fromYScale="1.0"android:pivotX="50%"android:pivotY="50%"android:toYScale="0.5"android:toXScale="0.5"/><alphaandroid:fromAlpha="1.0"android:toAlpha="0.0"/> </set> 4、在WelcomActivity.java中加載頁面布局和動畫, public void onAnimationEnd(Animation animation)//在動畫結束后跳轉到MainActivity
<span style="font-size:14px;">//WelcomActivity.java</span> package com.sunny.csdnblog;import android.app.Activity; import android.os.Bundle; import android.os.Handler; import android.view.Window; import android.view.animation.AnimationUtils; import android.view.animation.Animation; import android.view.animation.Animation.AnimationListener; import android.content.Intent;import android.view.View; import android.widget.ImageView; import android.widget.TextView; public class WelcomActivity extends Activity{private Handler mHandler;@Overrideprotected void onCreate(Bundle savedInstanceState){super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.welcom_layout);mHandler = new Handler();//TextView welcomTextView = (TextView)findViewById(R.id.welcomImage);//TextView madebyTextView = (TextView)findViewById(R.id.madeby);View welcomView = (View)findViewById(R.id.welcom_layout);Animation animation = AnimationUtils.loadAnimation(this, R.anim.welcom_anim);animation.setAnimationListener(new AnimationListener(){@Overridepublic void onAnimationStart(Animation animation) {// TODO Auto-generated method stub}@Overridepublic void onAnimationEnd(Animation animation) {// TODO Auto-generated method stubmHandler.post(new Runnable(){@Overridepublic void run() {// TODO Auto-generated method stubIntent intent = new Intent(WelcomActivity.this,MainActivity.class);startActivity(intent);WelcomActivity.this.finish();}});}@Overridepublic void onAnimationRepeat(Animation animation) {// TODO Auto-generated method stub}});welcomView.startAnimation(animation);//madebyTextView.startAnimation(animation);}}
5、MainActivity顯示一個頁面head和一個WebView
public class MainActivity extends FragmentActivity {private WebView webView;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.activity_main);webView = (WebView)findViewById(R.id.webView);webView.getSettings().setJavaScriptEnabled(true);webView.setWebViewClient(new WebViewClient());webView.loadUrl("http://blog.csdn.net/doudoulee_blog");} }
總結
- 上一篇: 最可怕的十大电脑病毒(十大最危险的电脑病
- 下一篇: 迅雷电脑单机游戏下载(迅雷单机游戏资源)