西西软件下载最安全的下载网站、值得信赖的软件下载站!

首页编程开发Android → android 第一次运行应用的引导界面

android 第一次运行应用的引导界面

相关软件相关文章发表评论 来源:西西整理时间:2012/12/8 9:16:12字体大小:A-A+

作者:西西点击:5次评论:0次标签: android

  • 类型:源码相关大小:23.6M语言:中文 评分:9.1
  • 标签:
立即下载

引导画面该如何才能较好的适配各种分辨率,了解此处有助于更好的定义引导画面,以及保持同设计师、工程师的良好沟通。.
android引导界面,实现了指示器的动画效果,不是固定在图片里面写死的。这样的用户体验更好。.

先看看效果图:

主要代码:

package com.example.introducedemo;

import java.util.ArrayList;

import android.app.Activity;
import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup.LayoutParams;
import android.view.Window;
import android.widget.ImageView;
import android.widget.LinearLayout;

public class MainActivity extends Activity {
    private ImageView mImageView;
    View mView;
    private ArrayList<View> mPageViews;
    // 定义LayoutInflater
    LayoutInflater mInflater;
    private ViewPager mViewPager;
    LinearLayout mLinearLayout;
    private ImageView[] mImageViews;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // 设置窗口无标题
        requestWindowFeature(Window.FEATURE_NO_TITLE);
        mInflater = getLayoutInflater();

        mPageViews = new ArrayList<View>();
        mPageViews.add(mInflater.inflate(R.layout.view_01, null));
        mPageViews.add(mInflater.inflate(R.layout.view_02, null));
        mPageViews.add(mInflater.inflate(R.layout.view_03, null));
        mImageViews = new ImageView[mPageViews.size()];
        mView = mInflater.inflate(R.layout.activity_main, null);
        mViewPager = (ViewPager) mView.findViewById(R.id.myviewpager);
        mLinearLayout = (LinearLayout) mView
                .findViewById(R.id.mybottomviewgroup);
        for (int i = 0; i < mImageViews.length; i++) {
            mImageView = new ImageView(MainActivity.this);
            mImageView.setLayoutParams(new LayoutParams(10, 10));
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
                    LinearLayout.LayoutParams.WRAP_CONTENT,
                    LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(10, 0, 10, 0);
            mImageView.setLayoutParams(lp);

            if (i == 0) {
                mImageView.setBackgroundResource(R.drawable.page_indicator_focused);
            } else {
                mImageView
                        .setBackgroundResource(R.drawable.page_indicator_unfocused);
            }

            mImageViews[i] = mImageView;

            // 把指示作用的远点图片加入底部的视图中
            mLinearLayout.addView(mImageViews[i]);
        }
        setContentView(mView);
        mViewPager.setAdapter(new MyPagerAdapter());
        mViewPager.setOnPageChangeListener(new OnPageChangeListener() {
            public void onPageSelected(int arg0) {
                for (int i = 0; i < mImageViews.length; i++) {
                    if (i == arg0) {
                        mImageViews[i]
                                .setBackgroundResource(R.drawable.page_indicator_focused);
                    } else {
                        mImageViews[i]
                                .setBackgroundResource(R.drawable.page_indicator_unfocused);
                    }
                }
            }

            @Override
            public void onPageScrolled(int arg0, float arg1, int arg2) {
                // TODO Auto-generated method stub

            }

            @Override
            public void onPageScrollStateChanged(int arg0) {
                // TODO Auto-generated method stub

            }
        });
    }

    class MyPagerAdapter extends PagerAdapter {

        @Override
        public int getCount() {
            return mPageViews.size();
        }

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

        @Override
        public int getItemPosition(Object object) {
            // TODO Auto-generated method stub
            return super.getItemPosition(object);
        }

        @Override
        public void destroyItem(View arg0, int arg1, Object arg2) {
            // TODO Auto-generated method stub
            ((ViewPager) arg0).removeView(mPageViews.get(arg1));
        }

        @Override
        public Object instantiateItem(View arg0, int arg1) {
            // TODO Auto-generated method stub
            ((ViewPager) arg0).addView(mPageViews.get(arg1));
            return mPageViews.get(arg1);
        }

        @Override
        public void restoreState(Parcelable arg0, ClassLoader arg1) {
            // TODO Auto-generated method stub

        }

        @Override
        public Parcelable saveState() {
            // TODO Auto-generated method stub
            return null;
        }

        @Override
        public void startUpdate(View arg0) {
            // TODO Auto-generated method stub

        }

        @Override
        public void finishUpdate(View arg0) {
            // TODO Auto-generated method stub

        }

    }
}

    相关评论

    阅读本文后您有什么感想? 已有人给出评价!

    • 8 喜欢喜欢
    • 3 顶
    • 1 难过难过
    • 5 囧
    • 3 围观围观
    • 2 无聊无聊

    热门评论

    最新评论

    发表评论 查看所有评论(0)

    昵称:
    表情: 高兴 可 汗 我不要 害羞 好 下下下 送花 屎 亲亲
    字数: 0/500 (您的评论需要经过审核才能显示)