編輯:Android開發實例
基於 實戰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();
- }
- }
- 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應用中都有。
五、運行效果圖:
轉自:http://blog.csdn.net/android_ls/article/details/8711766
unity3d發布apk在android虛擬機中運行的詳細步驟(unity3d導出android apk),總的流程分為以下6個步驟: 1、安裝java_jdk
本文實例講述了Android中ListView下拉刷新的實現方法。分享給大家供大家參考,具體如下: ListView中的下拉刷新是非常常見的,也是經常使用的,看
可以顯示在的Android任務,通過加載進度條的進展。進度條有兩種形狀。加載欄和加載微調(spinner)。在本章中,我們將討論微調(spinner)。Spinner 用
登錄應用程序的屏幕,詢問憑據登錄到一些特定的應用。可能需要登錄到Facebook,微博等本章介紹了,如何創建一個登錄界面,以及如何管理安全問題和錯誤嘗試。首先,必須定義兩