国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 系統(tǒng) > Android > 正文

Android引導(dǎo)界面的實現(xiàn)方法

2020-02-21 17:31:08
字體:
供稿:網(wǎng)友

現(xiàn)在越來越多程序都有引導(dǎo)頁面了,網(wǎng)上資料不夠齊全不全,今天我們就在這里,自己實現(xiàn)下吧,我們從中體驗樂趣,也是不錯的,好啦,那我們行動起來吧,和武林技術(shù)小編一起來領(lǐng)略下Android引導(dǎo)界面的實現(xiàn)方法。

?

/**
?* 實現(xiàn)
?* @author dujinyang
?*
?*/


順序是: OneAcitivity? -->MainActivity -> TwoActivity

?

然后第2次進(jìn)去就是:OneActivity -> TwoActivity

代碼里都有注釋的了,這里就不多說了。
OneActivity的代碼如下:

[java]

?

package cn.djy.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

/**
?* 開機(jī)動畫
?* @author Administrator
?*
?*/
public class OneActivity extends Activity {

??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? // TODO Auto-generated method stub?
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.one);

??????? boolean flag=this.isFirstEnter(getApplicationContext(), this.getClass().getName());
??????? if(flag)
??????????? mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY,4000);
??????? else
??????????? mHandler.sendEmptyMessageDelayed(SWITCH_TWOACTIVITY, 4000);

??? }

??? //***********************************************************************?
??? //判斷應(yīng)用是否初次加載,讀取SharedPreferences 的字段?
??? //***********************************************************************?
??? private static final String SHAREDPREFERENCES_NAME="yang";
??? private static final String KEY_GUIDE_ACTIVITY="Open";
??? /**
???? * mResultStr.equalsIgnoreCase("false") 返回FALSE
???? * TRUE 則為空值
???? * @param context
???? * @param className
???? * @return boolean
???? */
??? private boolean isFirstEnter(Context context,String className){
??????? if(context==null || className ==null || "".equalsIgnoreCase(className)) return false;
??????? String mResultStr=context.getSharedPreferences(SHAREDPREFERENCES_NAME,Context.MODE_WORLD_READABLE).getString(KEY_GUIDE_ACTIVITY, "");
??????? if(mResultStr.equalsIgnoreCase("false"))
??????????? return false;
??????? else
??????????? return true;
??? }

????
??? //****************************************?
??? //Handler:跳轉(zhuǎn)至不同頁面?
??? //****************************************?
??? private final static int SWITCH_TWOACTIVITY=1000; //主頁?

??? private final static int SWITCH_GUIDACTIVITY=1001; //滑動手勢?
??? private Handler mHandler=new Handler(){
??????? public void handleMessage(android.os.Message msg) {
??????????? switch (msg.what) {
??????????? case SWITCH_TWOACTIVITY:
??????????????????? Intent intent=new Intent();
??????????????????? intent.setClass(OneActivity.this,TwoActivity.class);
??????????????????? OneActivity.this.startActivity(intent);
??????????????? //? OneActivity.this.finish();?
??????????????? break;
??????????? case SWITCH_GUIDACTIVITY:
??????????????????? Intent intents=new Intent();
??????????????????? intents.setClass(OneActivity.this,MainActivity.class);
??????????????????? OneActivity.this.startActivity(intents);
??????????????? //? OneActivity.this.finish();?
??????????????????? break;
??????????? }
??????????? super.handleMessage(msg);
??????? };
??? };

}

?

package cn.djy.activity;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;

/**
?* 開機(jī)動畫
?* @author Administrator
?*
?*/
public class OneActivity extends Activity {

?@Override
?protected void onCreate(Bundle savedInstanceState) {
? // TODO Auto-generated method stub
? super.onCreate(savedInstanceState);
? setContentView(R.layout.one);

? boolean flag=this.isFirstEnter(getApplicationContext(), this.getClass().getName());
? if(flag)
?? mHandler.sendEmptyMessageDelayed(SWITCH_GUIDACTIVITY,4000);
? else
?? mHandler.sendEmptyMessageDelayed(SWITCH_TWOACTIVITY, 4000);

?}

?//***********************************************************************
?//判斷應(yīng)用是否初次加載,讀取SharedPreferences 的字段
?//***********************************************************************
?private static final String SHAREDPREFERENCES_NAME="yang";
?private static final String KEY_GUIDE_ACTIVITY="Open";
?/**
? * mResultStr.equalsIgnoreCase("false") 返回FALSE
? * TRUE 則為空值
? * @param context
? * @param className
? * @return boolean
? */
?private boolean isFirstEnter(Context context,String className){
? if(context==null || className ==null || "".equalsIgnoreCase(className)) return false;
? String mResultStr=context.getSharedPreferences(SHAREDPREFERENCES_NAME,Context.MODE_WORLD_READABLE).getString(KEY_GUIDE_ACTIVITY, "");
? if(mResultStr.equalsIgnoreCase("false"))
?? return false;
? else
?? return true;
?}

?
?//****************************************
?//Handler:跳轉(zhuǎn)至不同頁面
?//****************************************
?private final static int SWITCH_TWOACTIVITY=1000; //主頁

?private final static int SWITCH_GUIDACTIVITY=1001; //滑動手勢
?private Handler mHandler=new Handler(){
? public void handleMessage(android.os.Message msg) {
?? switch (msg.what) {
?? case SWITCH_TWOACTIVITY:
???? Intent intent=new Intent();
???? intent.setClass(OneActivity.this,TwoActivity.class);
???? OneActivity.this.startActivity(intent);
??? // OneActivity.this.finish();
??? break;
?? case SWITCH_GUIDACTIVITY:
???? Intent intents=new Intent();
???? intents.setClass(OneActivity.this,MainActivity.class);
???? OneActivity.this.startActivity(intents);
??? // OneActivity.this.finish();
???? break;
?? }
?? super.handleMessage(msg);
? };
?};

}

?

MainActivity的代碼如下:

[java]

?

package cn.djy.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
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.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TwoLineListItem;
/**
?* 實現(xiàn)
?* @author dujinyang
?*
?*/
public class MainActivity extends Activity {

??? private ViewPager _viewpager;

??? /**
???? * 分頁顯示的View數(shù)組
???? */
??? private ArrayList<View> _pagerlist;
??? private ImageView image;

??? /**
???? * 小圓點的圖片 放進(jìn)數(shù)組
???? */
??? private ImageView[] _imageViews;

??? //包裹滑動的圖片Linearlayout?
??? private ViewGroup _group;

??? //包裹小圓點的Linearlayout?
??? private ViewGroup _viewPonits;

????

????
??? /** Called when the activity is first created. */
??? @Override
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.start);

??????? LayoutInflater inflater=getLayoutInflater();
??????? _pagerlist =new ArrayList<View>();
??????? _pagerlist.add(inflater.inflate(R.layout.viewpager_page1,null));
??????? _pagerlist.add(inflater.inflate(R.layout.viewpager_page2,null));

??????? //創(chuàng)建Imageviews數(shù)組,大小是要顯示的圖片數(shù)量?
??????? _imageViews =new ImageView[_pagerlist.size()];

????????

//??????? ViewGroup??
??????? _group =(ViewGroup) inflater.inflate(R.layout.start, null);//加載MAIN.XML?

??????? _viewPonits=(ViewGroup) _group.findViewById(R.id.icon_circle);//加載小圓點的圖片?

??????? _viewpager =(ViewPager) _group.findViewById(R.id.guidePages);//android.support.v4.view.ViewPager?

????????
??????? //添加小圓點的圖片?
??????? for (int i = 0; i < _imageViews.length; i++) {
???????????? image= new ImageView(this);
???????????? //設(shè)置小圓點的imageview的參數(shù)?
???????????? image.setLayoutParams(new LayoutParams(20,20));//寬高均為20?
???????????? image.setPadding(20, 0, 20, 0);
???????????? _imageViews[i]=image;

???????????? //第一張是選中狀態(tài)?
???????????? if(i==0){
???????????????? _imageViews[i].setBackgroundResource(R.drawable.a2a);
???????????? }else{
???????????????? _imageViews[i].setBackgroundResource(R.drawable.a1a);
???????????? }
???????????? _viewPonits.addView(_imageViews[i]);
??????? }
??????? //顯示視圖?
??????? setContentView(_group);
??????? _viewpager.setAdapter(new GuidePageAdapter());
??????? _viewpager.setOnPageChangeListener(new GuidePageChangeListener());
??? }

????
??? void setGuided(){
??????? SharedPreferences shared=getSharedPreferences("yang",0);
??????? SharedPreferences.Editor editor=shared.edit();
??????? editor.putString("Open", "false");
??????? editor.commit();
??? }

??? class GuidePageAdapter extends PagerAdapter{

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

??????? //initalization position page?
??????? @Override
??????? public Object instantiateItem(View container, int position) {
??????????? ((ViewPager)container).addView(_pagerlist.get(position));
??????????? if(position==1){
??????????????? Button bt=(Button) container.findViewById(R.id.bt_close);
??????????????? bt.setOnClickListener(new OnClickListener() {
??????????????????? @Override
??????????????????? public void onClick(View v) {
??????????????????????? //設(shè)置已經(jīng)引導(dǎo)?
??????????????????????? setGuided();
??????????????????????? //Intent??
??????????????????????? Intent intent=new Intent();
??????????????????????? intent.setClass(MainActivity.this,TwoActivity.class );
??????????????????????? MainActivity.this.startActivity(intent);
??????????????????????? MainActivity.this.finish();
??????????????????? }
??????????????? });

??????????? }
??????????? return _pagerlist.get(position);
??????? }

????????
??????? //判斷是否由對象生成頁面?
??????? @Override
??????? public boolean isViewFromObject(View view, Object obj) {
??????????? return view==obj;
??????? }

??????? //銷毀頁面的位置?
??????? @Override
??????? public void destroyItem(View container, int position, Object object) {
??????????? ((ViewPager)container).removeView(_pagerlist.get(position));
??????? }

????????
??????? @Override
??????? public void finishUpdate(View container) {
??????????? //finish?
??????? }

??????? @Override
??????? public void startUpdate(View container) {
??????????? //start?
??????? }

??????? @Override
??????? public int getItemPosition(Object object) {
??????????? //getItemPosition?
??????????? return super.getItemPosition(object);
??????? }

????????
??????? @Override
??????? public void restoreState(Parcelable state, ClassLoader loader) {
??????????? super.restoreState(state, loader);
??????????? //restore?
??????? }

??????? @Override
??????? public Parcelable saveState() {
??????????? return super.saveState();
??????????? //save?
??????? }
??? }

??? class GuidePageChangeListener implements OnPageChangeListener{

??????? @Override
??????? public void onPageScrollStateChanged(int arg0) {

??????? }

??????? @Override
??????? public void onPageScrolled(int arg0, float arg1, int arg2) {

??????? }

??????? @Override
??????? public void onPageSelected(int position) {
??????????? for (int i = 0; i < _imageViews.length; i++) {
??????????????????? _imageViews[position].setBackgroundResource(R.drawable.a2a);
??????????????????? if(position!=i)
??????????????????????? _imageViews[i].setBackgroundResource(R.drawable.a1a);

??????????? }
??????? }

??? }
}

?

package cn.djy.activity;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
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.View.OnClickListener;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TwoLineListItem;
/**
?* 實現(xiàn)
?* @author dujinyang
?*
?*/
public class MainActivity extends Activity {

?private ViewPager _viewpager;

?/**
? * 分頁顯示的View數(shù)組
? */
?private ArrayList<View> _pagerlist;
?private ImageView image;

?/**
? * 小圓點的圖片 放進(jìn)數(shù)組
? */
?private ImageView[] _imageViews;

?//包裹滑動的圖片Linearlayout
?private ViewGroup _group;

?//包裹小圓點的Linearlayout
?private ViewGroup _viewPonits;

?

?
??? /** Called when the activity is first created. */
??? @Override
??? public void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.start);

??????? LayoutInflater inflater=getLayoutInflater();
??????? _pagerlist =new ArrayList<View>();
??????? _pagerlist.add(inflater.inflate(R.layout.viewpager_page1,null));
??????? _pagerlist.add(inflater.inflate(R.layout.viewpager_page2,null));

??????? //創(chuàng)建Imageviews數(shù)組,大小是要顯示的圖片數(shù)量
??????? _imageViews =new ImageView[_pagerlist.size()];

??????

//??????? ViewGroup
??????? _group =(ViewGroup) inflater.inflate(R.layout.start, null);//加載MAIN.XML

??????? _viewPonits=(ViewGroup) _group.findViewById(R.id.icon_circle);//加載小圓點的圖片

??????? _viewpager =(ViewPager) _group.findViewById(R.id.guidePages);//android.support.v4.view.ViewPager

??????
??????? //添加小圓點的圖片
??????? for (int i = 0; i < _imageViews.length; i++) {
??? image= new ImageView(this);
??? //設(shè)置小圓點的imageview的參數(shù)
??? image.setLayoutParams(new LayoutParams(20,20));//寬高均為20
??? image.setPadding(20, 0, 20, 0);
??? _imageViews[i]=image;

??? //第一張是選中狀態(tài)
??? if(i==0){
???? _imageViews[i].setBackgroundResource(R.drawable.a2a);
??? }else{
???? _imageViews[i].setBackgroundResource(R.drawable.a1a);
??? }
??? _viewPonits.addView(_imageViews[i]);
? }
??????? //顯示視圖
??????? setContentView(_group);
??????? _viewpager.setAdapter(new GuidePageAdapter());
??????? _viewpager.setOnPageChangeListener(new GuidePageChangeListener());
??? }

??
??? void setGuided(){
???? SharedPreferences shared=getSharedPreferences("yang",0);
???? SharedPreferences.Editor editor=shared.edit();
???? editor.putString("Open", "false");
???? editor.commit();
??? }

??? class GuidePageAdapter extends PagerAdapter{

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

? //initalization position page
? @Override
? public Object instantiateItem(View container, int position) {
?? ((ViewPager)container).addView(_pagerlist.get(position));
?? if(position==1){
??? Button bt=(Button) container.findViewById(R.id.bt_close);
??? bt.setOnClickListener(new OnClickListener() {
???? @Override
???? public void onClick(View v) {
????? //設(shè)置已經(jīng)引導(dǎo)
????? setGuided();
????? //Intent
????? Intent intent=new Intent();
????? intent.setClass(MainActivity.this,TwoActivity.class );
????? MainActivity.this.startActivity(intent);
????? MainActivity.this.finish();
???? }
??? });

?? }
?? return _pagerlist.get(position);
? }

?
? //判斷是否由對象生成頁面
? @Override
? public boolean isViewFromObject(View view, Object obj) {
?? return view==obj;
? }

? //銷毀頁面的位置
? @Override
? public void destroyItem(View container, int position, Object object) {
?? ((ViewPager)container).removeView(_pagerlist.get(position));
? }

?
? @Override
? public void finishUpdate(View container) {
?? //finish
? }

? @Override
? public void startUpdate(View container) {
?? //start
? }

? @Override
? public int getItemPosition(Object object) {
?? //getItemPosition
?? return super.getItemPosition(object);
? }

?
? @Override
? public void restoreState(Parcelable state, ClassLoader loader) {
?? super.restoreState(state, loader);
?? //restore
? }

? @Override
? public Parcelable saveState() {
?? return super.saveState();
?? //save
? }
??? }

??? class GuidePageChangeListener implements OnPageChangeListener{

? @Override
? public void onPageScrollStateChanged(int arg0) {

? }

? @Override
? public void onPageScrolled(int arg0, float arg1, int arg2) {

? }

? @Override
? public void onPageSelected(int position) {
?? for (int i = 0; i < _imageViews.length; i++) {
???? _imageViews[position].setBackgroundResource(R.drawable.a2a);
???? if(position!=i)
????? _imageViews[i].setBackgroundResource(R.drawable.a1a);

?? }
? }

??? }
}

?

?

最后是TWOActivity:這個Activity是顯示的內(nèi)容。

[java]

?

package cn.djy.activity;

import android.app.Activity;
import android.os.Bundle;

public class TwoActivity extends Activity{

????
??? @Override
??? protected void onCreate(Bundle savedInstanceState) {
??????? super.onCreate(savedInstanceState);
??????? setContentView(R.layout.end);
??? }

}

?

package cn.djy.activity;

import android.app.Activity;
import android.os.Bundle;

public class TwoActivity extends Activity{

?
?@Override
?protected void onCreate(Bundle savedInstanceState) {
? super.onCreate(savedInstanceState);
? setContentView(R.layout.end);
?}

}

?

主要代碼完成。
里面涉及的drawable圖片是小圓點圖片。

下面貼出XML的。

start.xml

?

[css]

?

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

??????? <android.support.v4.view.ViewPager?? android:id="@+id/guidePages" android:layout_width="fill_parent"? android:layout_height="wrap_content"/>

???? </LinearLayout>

?????

???? <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linear_circle">

???????? <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
??????????????? <LinearLayout android:id="@+id/icon_circle"?
????????????????????????????? android:layout_width="fill_parent"?
????????????????????????????? android:layout_height="wrap_content"?
????????????????????????????? android:layout_marginBottom="40dip"?
????????????????????????????? android:layout_alignParentBottom="true"?
????????????????????????????? android:gravity="center_vertical"
????????????????????????????? android:orientation="horizontal"/>
???????? </RelativeLayout>

???? </LinearLayout>

</FrameLayout>

?

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

??? <android.support.v4.view.ViewPager? android:id="@+id/guidePages" android:layout_width="fill_parent"? android:layout_height="wrap_content"/>

?? </LinearLayout>
?? <LinearLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" android:id="@+id/linear_circle">

???? <RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" >
?????? <LinearLayout android:id="@+id/icon_circle"
??????????? android:layout_width="fill_parent"
??????????? android:layout_height="wrap_content"
??????????? android:layout_marginBottom="40dip"
??????????? android:layout_alignParentBottom="true"
??????????? android:gravity="center_vertical"
??????????? android:orientation="horizontal"/>
???? </RelativeLayout>

?? </LinearLayout>

</FrameLayout>


其實是用Group把子項包起來作為顯示:

?

那子項為:
viewpager_page1.xml

[css]

?

<LinearLayout
? xmlns:android="http://schemas.android.com/apk/res/android"
? android:layout_width="match_parent"
? android:layout_height="match_parent"? android:orientation="vertical">
?? <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="adfasfasfweqwwfqw'"
?? />
?</LinearLayout>

?

<LinearLayout
? xmlns:android="http://schemas.android.com/apk/res/android"
? android:layout_width="match_parent"
? android:layout_height="match_parent"? android:orientation="vertical">
?? <TextView android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="center" android:text="adfasfasfweqwwfqw'"
?? />
?</LinearLayout>
?


viewpager_page2.xml

?

[css]

?

<?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:gravity="center">

? <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="pages222222222222222222"></TextView>

? <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="asdfi14234124" android:id="@+id/bt_close"></Button>
</LinearLayout>

?

<?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:gravity="center">

? <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="pages222222222222222222"></TextView>

? <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="asdfi14234124" android:id="@+id/bt_close"></Button>
</LinearLayout>

關(guān)于Android引導(dǎo)界面的實現(xiàn)方法就講完啦,如果大家還有疑問歡迎給武林小編留言,小編會及時回復(fù)大家的,同時在這里感謝大家對武林技術(shù)頻道的支持!

發(fā)表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發(fā)表
主站蜘蛛池模板: 游戏| 名山县| 平昌县| 靖远县| 阿鲁科尔沁旗| 玛沁县| 宜君县| 墨竹工卡县| 乌什县| 金平| 香港 | 卢湾区| 天台县| 昌乐县| 申扎县| 信宜市| 平南县| 雷波县| 玛多县| 昆山市| 康乐县| 江西省| 体育| 长宁县| 广西| 盘山县| 永川市| 永济市| 巨野县| 永登县| 商南县| 宁阳县| 新源县| 双柏县| 吴江市| 锦屏县| 蓬安县| 淳化县| 高青县| 五大连池市| 萨迦县|