Android仿人人用戶端(v5.7.1)——歡迎和導引介面的編碼實現

來源:互聯網
上載者:User

轉載請標明出處:http://blog.csdn.net/android_ls/article/details/8711766
 聲明:仿人人項目,所用所有圖片資源都來源於官方人人android用戶端,編寫本應用的目的在於學習交流,如涉及侵權請告知,我會及時換掉用到的相關圖片。

一、應用程式框架搭建,自訂類繼承Application,用於存放全域變數和公用的資源等,代碼如下:

package com.copyeveryone.android;import java.util.LinkedList;import java.util.List;import android.app.Activity;import android.app.Application;/** * 功能描述:用於存放全域變數和公用的資源等 * @author android_ls */public class CopyEveryoneApplication extends Application {    private List<Activity> activitys = new LinkedList<Activity>();    // 應用程式的入口    @Override    public void onCreate() {    }    public void addActivity(Activity activity) {        activitys.add(activity);    }    @Override    public void onTerminate() {        for (Activity activity : activitys) {            activity.finish();        }        System.exit(0);    }}

二、應用中介面(Activity)的基類,代碼如下:

package com.copyeveryone.android;import android.app.Activity;import android.os.Bundle;import android.widget.Toast;/** * 功能描述:應用中介面(Activity)的基類 * 對原有的Activity類進行擴充 * @author android_ls */public abstract class AppBaseActivity extends Activity {    @Override    protected void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        ((CopyEveryoneApplication) this.getApplication()).addActivity(this);        setContentView(getLayoutId());        // 初始化組件        setupView();        // 初始化資料        initializedData();    }    /**     * 布局檔案ID     * @return     */    protected abstract int getLayoutId();    /**     * 初始化組件     */    protected abstract void setupView();    /**     * 初始化資料     */    protected abstract void initializedData();    /**     * 顯示Toast形式的提示資訊     * @param message     */    protected void show(String message) {        Toast.makeText(getApplicationContext(), message, Toast.LENGTH_LONG).show();    }}

三、歡迎介面(LOGO)的實現,代碼如下:

package com.copyeveryone.android.ui;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.os.CountDownTimer;import com.copyeveryone.android.R;/** * 功能描述:歡迎介面(LOGO) * @author android_ls */public class WelcomeActivity extends Activity {    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        setContentView(R.layout.welcome);        new CountDownTimer(1000, 1000) {            @Override            public void onTick(long millisUntilFinished) {                // TODO Auto-generated method stub            }            @Override            public void onFinish() {                Intent intent = new Intent(WelcomeActivity.this, GuideActivity.class);                startActivity(intent);                WelcomeActivity.this.finish();            }        }.start();    }}

布局檔案welcome.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:background="@drawable/v5_0_1_welcome"    android:orientation="vertical" />

四、導引介面的實現,介面效果動畫原理:每張圖片都執行的動畫順序,漸現、放大和漸隱,結束後切換圖片和文字又開始執行 漸現、放大和漸隱...,當最後一張執行完漸隱,切換到第一張,從而達到迴圈效果。具體代碼如下:

package com.copyeveryone.android.ui;import android.graphics.drawable.Drawable;import android.os.Bundle;import android.view.View;import android.view.animation.Animation;import android.view.animation.Animation.AnimationListener;import android.view.animation.AnimationUtils;import android.widget.Button;import android.widget.ImageView;import android.widget.TextView;import com.copyeveryone.android.AppBaseActivity;import com.copyeveryone.android.R;/** * 功能描述:導引介面 * 介面效果動畫原理:每張圖片都執行的動畫順序,漸現、放大和漸隱,結束後切換圖片和文字 * 又開始執行 漸現、放大和漸隱...,當最後一張執行完漸隱,切換到第一張,從而達到迴圈效果。 * @author android_ls */public class GuideActivity extends AppBaseActivity implements View.OnClickListener {    /**     * 註冊按鈕     */    private Button btnRegister;    /**     * 看看我認識的人按鈕     */    private Button btnLookAtThePeopleIKnow;    /**     * 登入按鈕     */    private Button btnLogin;    /**     * 顯示圖片的ImageView組件     */    private ImageView ivGuidePicture;    /**     * 顯示圖片的對應的文字描述文本組件     */    private TextView tvGuideContent;    /**     * 要展示的一組圖片資源     */    private Drawable[] pictures;    /**     * 每張展示圖片要執行的一組動畫效果     */    private Animation[] animations;    /**     * 當前執行的是第幾張圖片(資源索引)     */    private int position = 0;    /**     * 要展示的圖片對應的文本描述(圖片與文字一一對應)     */    private String[] texts = { "兒時友,莫相忘", "同學情,請珍藏", "共奮鬥,同分享", "感謝一路有你", "青春勇敢飛翔", "理想從未遠去" };    @Override    public void onCreate(Bundle savedInstanceState) {        super.onCreate(savedInstanceState);        tvGuideContent.setText(texts[position]);        ivGuidePicture.setImageDrawable(pictures[position]);        ivGuidePicture.startAnimation(animations[0]);    }    @Override    protected int getLayoutId() {        return R.layout.guide;    }    @Override    protected void setupView() {        ivGuidePicture = (ImageView) findViewById(R.id.iv_guide_picture);        tvGuideContent = (TextView) findViewById(R.id.tv_guide_content);        btnRegister = (Button) findViewById(R.id.btn_register);        btnLookAtThePeopleIKnow = (Button) findViewById(R.id.btn_look_at_the_people_i_know);        btnLogin = (Button) findViewById(R.id.btn_login);        btnRegister.setOnClickListener(this);        btnLookAtThePeopleIKnow.setOnClickListener(this);        btnLogin.setOnClickListener(this);    }    @Override    protected void initializedData() {        pictures = new Drawable[] { getResources().getDrawable(R.drawable.v5_0_1_guide_pic1), getResources().getDrawable(R.drawable.v5_0_1_guide_pic2),                getResources().getDrawable(R.drawable.v5_0_1_guide_pic3), getResources().getDrawable(R.drawable.v5_3_0_guide_pic1),                getResources().getDrawable(R.drawable.v5_3_0_guide_pic2), getResources().getDrawable(R.drawable.v5_3_0_guide_pic3) };        animations = new Animation[] { AnimationUtils.loadAnimation(this, R.anim.v5_0_1_guide_welcome_fade_in),                AnimationUtils.loadAnimation(this, R.anim.v5_0_1_guide_welcome_fade_in_scale),                AnimationUtils.loadAnimation(this, R.anim.v5_0_1_guide_welcome_fade_out) };        animations[0].setDuration(1500);        animations[1].setDuration(3000);        animations[2].setDuration(1500);        animations[0].setAnimationListener(new GuideAnimationListener(0));        animations[1].setAnimationListener(new GuideAnimationListener(1));        animations[2].setAnimationListener(new GuideAnimationListener(2));    }    @Override    public void onClick(View v) {        switch (v.getId()) {        case R.id.btn_register:            show("抱歉,該功能暫未提供!");            break;        case R.id.btn_look_at_the_people_i_know:            show("抱歉,該功能暫未提供!");            break;        case R.id.btn_login:            break;        default:            break;        }    }    class GuideAnimationListener implements AnimationListener {        private int index;        public GuideAnimationListener(int index) {            this.index = index;        }        @Override        public void onAnimationStart(Animation animation) {            // TODO Auto-generated method stub        }        @Override        public void onAnimationEnd(Animation animation) {            if (index < (animations.length - 1)) {                ivGuidePicture.startAnimation(animations[index + 1]);            } else {                position++;                if (position > (pictures.length - 1)) {                    position = 0;                }                System.out.println("position = " + position);                tvGuideContent.setText(texts[position]);                ivGuidePicture.setImageDrawable(pictures[position]);                ivGuidePicture.startAnimation(animations[0]);            }        }        @Override        public void onAnimationRepeat(Animation animation) {        }    }}

布局檔案guide.xml:

<?xml version="1.0" encoding="utf-8"?><FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="fill_parent"    android:layout_height="fill_parent"    android:orientation="vertical" >    <RelativeLayout        android:layout_width="fill_parent"        android:layout_height="fill_parent"        android:orientation="vertical" >        <ImageView            android:id="@+id/iv_guide_picture"            android:layout_width="fill_parent"            android:layout_height="fill_parent"            android:layout_weight="1.0"            android:scaleType="fitXY" />        <LinearLayout            android:id="@+id/ll_bottom_action_bar"            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_alignParentBottom="true"            android:orientation="horizontal"            android:padding="7dip" >            <Button                android:id="@+id/btn_register"                android:layout_width="fill_parent"                android:layout_height="45dip"                android:layout_weight="1.5"                android:background="@drawable/guide_btn_blue_selector"                android:gravity="center"                android:singleLine="true"                android:text="注  冊"                android:textColor="#FFFFFF"                android:textSize="15.0sp" />            <Button                android:id="@+id/btn_look_at_the_people_i_know"                android:layout_width="fill_parent"                android:layout_height="45dip"                android:layout_marginLeft="8dip"                android:layout_marginRight="8dip"                android:layout_weight="1.0"                android:background="@drawable/guide_btn_white_selector"                android:gravity="center"                android:singleLine="true"                android:text="看看我認識的人"                android:textColor="#000000"                android:textSize="15.0sp" />            <Button                android:id="@+id/btn_login"                android:layout_width="fill_parent"                android:layout_height="45dip"                android:layout_weight="1.5"                android:background="@drawable/guide_btn_blue_selector"                android:gravity="center"                android:singleLine="true"                android:text="登  錄"                android:textColor="#FFFFFF"                android:textSize="15.0sp" />        </LinearLayout>        <LinearLayout            android:layout_width="fill_parent"            android:layout_height="wrap_content"            android:layout_above="@+id/ll_bottom_action_bar"            android:layout_marginBottom="40dip"            android:orientation="vertical" >            <TextView                android:id="@+id/tv_guide_content"                android:layout_width="wrap_content"                android:layout_height="wrap_content"                android:layout_gravity="center_horizontal"                android:gravity="center"                android:textColor="#FFFFFF"                android:textSize="25.0sp"                android:textStyle="bold" />        </LinearLayout>    </RelativeLayout></FrameLayout>

資源檔guide_btn_blue_selector.xml:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/v5_0_1_guide_blue_default" android:state_focused="true" android:state_pressed="false"/>    <item android:drawable="@drawable/v5_0_1_guide_blue_press" android:state_pressed="true"/>    <item android:drawable="@drawable/v5_0_1_guide_blue_default"/></selector>

資源檔guide_btn_white_selector.xml:

<?xml version="1.0" encoding="utf-8"?><selector xmlns:android="http://schemas.android.com/apk/res/android">    <item android:drawable="@drawable/v5_0_1_guide_black_default" android:state_focused="true" android:state_pressed="false"/>    <item android:drawable="@drawable/v5_0_1_guide_black_press" android:state_pressed="true"/>    <item android:drawable="@drawable/v5_0_1_guide_black_default"/></selector>

漸入動畫資源檔案v5_0_1_guide_welcome_fade_in.xml:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <alpha        android:fromAlpha="0.0"        android:toAlpha="1.0" /></set>

放大動畫資源檔案v5_0_1_guide_welcome_fade_in_scale.xml:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <scale        android:fillAfter="false"        android:fromXScale="1.0"        android:fromYScale="1.0"        android:interpolator="@android:anim/decelerate_interpolator"        android:pivotX="50.0%"        android:pivotY="50.0%"        android:toXScale="1.1"        android:toYScale="1.1" /></set>

漸隱動畫資源檔案v5_0_1_guide_welcome_fade_out.xml:

<?xml version="1.0" encoding="utf-8"?><set xmlns:android="http://schemas.android.com/apk/res/android" >    <scale        android:fillAfter="false"        android:fromXScale="1.1"        android:fromYScale="1.1"        android:interpolator="@android:anim/decelerate_interpolator"        android:pivotX="50.0%"        android:pivotY="50.0%"        android:toXScale="1.1"        android:toYScale="1.1" />    <alpha        xmlns:android="http://schemas.android.com/apk/res/android"        android:fromAlpha="1.0"        android:toAlpha="0.0" /></set>

註:所涉及的圖片在人人官方的android應用中都有。

五、運行:

 

 

 

 

 

 

本來想錄段視頻,動畫效果才會一目瞭然,可惜我沒找到辦法。有哪位朋友知道的話,請麻煩告訴我。還有如何向CSDN上上傳視屏?

後面的內容待續。。。

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.