Androidフラッシュページとガイドページの作成


オリジナルコードの転載禁止!
本編はフラッシュページとガイドページの実現
知識点:
フラッシュ・ページ:パッチ・アニメーションの使用、SharedPreferences、タイマの使用方法
ブートページ:ViewPager,PagerAdapter,バインドデータソース,移動する小さなドット,ビューツリーを取得する
問題があったら、次のコメントをして、一緒に検討します.
まず、フラッシュ・ページの実装を見てみましょう.
import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.AnimationSet;
import android.view.animation.RotateAnimation;
import android.view.animation.ScaleAnimation;
import android.widget.RelativeLayout;

import java.util.Timer;
import java.util.TimerTask;

public class SplashActivity extends AppCompatActivity {
    RelativeLayout relativeLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash_activity);
        relativeLayout= (RelativeLayout) findViewById(R.id.relativeLayout);
        startAnimation();
        Timer timer=new Timer();
        TimerTask task =new TimerTask() {
            @Override
            public void run() {
                guide();
                finish();
            }
        };
        timer.schedule(task,6000);
    }
    private void startAnimation(){
        AnimationSet animationSet=new AnimationSet(false);

        RotateAnimation rotate=new RotateAnimation(0,360,
                Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        rotate.setDuration(5000);
        rotate.setFillAfter(true);

        ScaleAnimation scale=new ScaleAnimation(0,1,0,1,Animation.RELATIVE_TO_SELF,0.5f,
                Animation.RELATIVE_TO_SELF,0.5f);
        scale.setDuration(5000);
        scale.setFillAfter(true);

        AlphaAnimation alpha=new AlphaAnimation(0,1);
        alpha.setDuration(5000);
        alpha.setFillAfter(true);

        animationSet.addAnimation(rotate);
        animationSet.addAnimation(scale);
        animationSet.addAnimation(alpha);

        relativeLayout.startAnimation(animationSet);
    }

    public void guide(){
        //        
        SharedPreferences sharedPreferences = this.getSharedPreferences("share", MODE_PRIVATE);
        boolean isFirstRun = sharedPreferences.getBoolean("isFirstRun", true);
        SharedPreferences.Editor editor = sharedPreferences.edit();
        if (isFirstRun){
            Log.e("debug", "     ");
            editor.putBoolean("isFirstRun", false);
            editor.commit();
            Intent intent = new Intent();
            intent.setClass(SplashActivity.this,GuideActivity.class);
            startActivity(intent);
        } else {
            Log.e("debug", "       ");
            Intent intent = new Intent();
            intent.setClass(SplashActivity.this,MainActivity.class);
            startActivity(intent);
        }
    }
}

ブートページコードは次のように参照されます.
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewTreeObserver;
import android.view.Window;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;

import java.util.ArrayList;

/**
 * Created by Administrator on 2017/5/19 0019.
 */
public class GuideActivity extends Activity{
    private static final int[] mImageIds={R.drawable.guide_1,R.drawable.guide_2,R.drawable.guide_3};
    private ViewPager viewPager;
    private  ArrayList mImageViewList;
    private View viewRedPoint;
    private LinearLayout llPointGroup;//      
    private int mPointWidth;//      
    private Button start_button;
    @Override
    protected void onCreate( Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        requestWindowFeature(Window.FEATURE_NO_TITLE);//    
        setContentView(R.layout.guide_activity);
        viewPager=(ViewPager)findViewById(R.id.vp_guide);
        llPointGroup=(LinearLayout) findViewById(R.id.ll_point_group);
        viewRedPoint=(View)findViewById(R.id.view_red_point);
        viewPager.setAdapter(new GuideAdapter());
        viewPager.setOnPageChangeListener(new GuidePageListener());
        start_button = (Button) findViewById(R.id.buttonStart);
        start_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(GuideActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
        initViews();
    }
    /*
     *     
     */
    private void initViews(){
        mImageViewList = new ArrayList();
            //       3   
        for (int i=0;i0){
                params.leftMargin = 10;//      
            }
            point.setLayoutParams(params);//      

            llPointGroup.addView(point);//          
        }
        //     
        llPointGroup.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

            //  layout          
            @Override
            public void onGlobalLayout() {
//                    System.out.println("layout   ");
                llPointGroup.getViewTreeObserver().removeGlobalOnLayoutListener(this);
                //measure(    ) layout(    ) ondraw
                mPointWidth = llPointGroup.getChildAt(1).getLeft()-llPointGroup.getChildAt(0).getLeft();
//                System.out.println("    :"+mPointWidth);

            }
        });

    }
    /*
     *ViewPager    
     */

    class  GuideAdapter extends PagerAdapter{

        @Override
        public int getCount() {
            return mImageIds.length;
        }

        @Override
        public boolean isViewFromObject(View arg0, Object arg1) {
            return arg0==arg1;
        }

        @Override
        public Object instantiateItem(ViewGroup container, int position) {
            container.addView(mImageViewList.get(position));
            return mImageViewList.get(position);
        }

        @Override
        public void destroyItem(ViewGroup container, int position, Object object) {
            container.removeView((View)object);
        }
    }
    /*
     *  viewpager     
     */
    class GuidePageListener implements ViewPager.OnPageChangeListener{
        //    
        @Override
        public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

//            System.out.println("    :"+position +";   :" + positionOffset +
//                    ";    :"+positionOffsetPixels);
            int len = (int) (mPointWidth * positionOffset) + position * mPointWidth;
            RelativeLayout.LayoutParams Params= (RelativeLayout.LayoutParams)
                    viewRedPoint.getLayoutParams();//          
            Params.leftMargin = len;//     
            viewRedPoint.setLayoutParams(Params);//           
        }

        //       
        @Override
        public void onPageSelected(int position) {
            if ( position == mImageIds.length-1) {
                start_button.setVisibility(View.VISIBLE);
            }else{
                start_button.setVisibility(View.INVISIBLE);
            }
        }

        //        
        @Override
        public void onPageScrollStateChanged(int state) {

        }
    }

}