Welocm.java
package com.example.test;import androID.content.Intent;import androID.os.Bundle;import androID.vIEw.VIEw;import androID.vIEw.VIEwGroup;import androID.Widget.button;import androID.Widget.ImageVIEw;import androIDx.appcompat.app.AppCompatActivity;import androIDx.vIEwpager.Widget.PagerAdapter;import androIDx.vIEwpager.Widget.VIEwPager;import java.util.ArrayList;import java.util.List;import Share_tool.SharedPreferencesUtils;public class Welcome extends AppCompatActivity { private List<VIEw> vIEws; private button btn_guIDe; private VIEwPager vIEwPager; private ImageVIEw point1, point2, point3, point4; protected voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //判断是否第一次启动 Boolean isfirstlogin=SharedPreferencesUtils.getBoolean(Welcome.this,"isFirstLogin",false); if(isfirstlogin==true){ startActivity(new Intent(Welcome.this, MainActivity.class)); finish(); } setContentVIEw(R.layout.activity_splash); vIEwPager = (VIEwPager) findVIEwByID(R.ID.pager_guIDe); //绑定组件 btn_guIDe = findVIEwByID(R.ID.btn_guIDe); point1 = findVIEwByID(R.ID.point1); point2 = findVIEwByID(R.ID.point2); point3 = findVIEwByID(R.ID.point3); point4 = findVIEwByID(R.ID.point4); //初始化 initVIEwPager(); //设置适配器 vIEwPager.setAdapter(new GuIDeAdapter(vIEws)); vIEwPager.setPagetransformer(false, new DepthPagetransformer()); setPointimg(true, false, false, false); btn_guIDe.setonClickListener(new VIEw.OnClickListener() { public voID onClick(VIEw v) { SharedPreferencesUtils.saveBoolean(Welcome.this,"isFirstLogin",true); startActivity(new Intent(Welcome.this, MainActivity.class)); finish(); } }); } //初始化vIEwpager public voID initVIEwPager(){ vIEws=new ArrayList<VIEw>(); ImageVIEw iv1=new ImageVIEw(this); iv1.setimageResource(R.drawable.a1); iv1.setScaleType(ImageVIEw.ScaleType.FIT_XY); ImageVIEw iv2=new ImageVIEw(this); iv2.setimageResource(R.drawable.a2); iv2.setScaleType(ImageVIEw.ScaleType.FIT_XY); ImageVIEw iv3=new ImageVIEw(this); //为ImageVIEw添加图片资源 iv3.setimageResource(R.drawable.a3); //设置图片充满屏幕 iv3.setScaleType(ImageVIEw.ScaleType.FIT_XY); ImageVIEw iv4=new ImageVIEw(this); iv4.setimageResource(R.drawable.a4); iv4.setScaleType(ImageVIEw.ScaleType.FIT_XY); vIEws.add(iv1); vIEws.add(iv2); vIEws.add(iv3); vIEws.add(iv4); vIEwPager.addOnPagechangelistener(new VIEwPager.OnPagechangelistener() { @OverrIDe public voID onPageScrolled(int position, float positionOffset, int positionOffsetPixels) { } //pager切换 @OverrIDe public voID onPageSelected(int position) { //如果是第三个页面就显示按钮,反之不显示 switch (position) { case 0: setPointimg(true, false, false, false); btn_guIDe.setVisibility(VIEw.GONE); break; case 1: setPointimg(false, true, false, false); btn_guIDe.setVisibility(VIEw.GONE); break; case 2: setPointimg(false, false, true, false); btn_guIDe.setVisibility(VIEw.GONE); break; case 3: setPointimg(false, false, false, true); btn_guIDe.setVisibility(VIEw.VISIBLE); break; } } @OverrIDe public voID onPageScrollStateChanged(int state) { } }); } //设置适配器 class GuIDeAdapter extends PagerAdapter { private List<VIEw> vIEws; public GuIDeAdapter(List<VIEw> v){ this.vIEws=v; } public int getCount() { return vIEws.size(); } @OverrIDe public boolean isVIEwFromObject(VIEw vIEw, Object object) { return vIEw == object; } @OverrIDe public Object instantiateItem(VIEwGroup container, int position) { ((VIEwPager) container).addVIEw(vIEws.get(position)); return vIEws.get(position); } @OverrIDe public voID destroyItem(VIEwGroup container, int position, Object object) { ((VIEwPager) container).removeVIEw(vIEws.get(position)); //super.destroyItem(container, position, object); } } //动画切换特效 public class DepthPagetransformer implements VIEwPager.Pagetransformer { private static final float MIN_SCALE = 0.75f; public voID transformPage(VIEw vIEw, float position) { int pageWIDth = vIEw.getWIDth(); if (position < -1) { // [-Infinity,-1) // This page is way off-screen to the left. vIEw.setAlpha(0); } else if (position <= 0) { // [-1,0] // Use the default slIDe Transition when moving to the left page vIEw.setAlpha(1); vIEw.setTranslationX(0); vIEw.setScaleX(1); vIEw.setScaleY(1); } else if (position <= 1) { // (0,1] // Fade the page out. vIEw.setAlpha(1 - position); // Counteract the default slIDe Transition vIEw.setTranslationX(pageWIDth * -position); // Scale the page down (between MIN_SCALE and 1) float scaleFactor = MIN_SCALE + (1 - MIN_SCALE) * (1 - Math.abs(position)); vIEw.setScaleX(scaleFactor); vIEw.setScaleY(scaleFactor); } else { // (1,+Infinity] // This page is way off-screen to the right. vIEw.setAlpha(0); } } } //设置小圆点的选中效果 private voID setPointimg(boolean isCheck1, boolean isCheck2, boolean isCheck3, boolean isCheck4) { if (isCheck1) { point1.setBackgroundResource(R.drawable.point_on); } else { point1.setBackgroundResource(R.drawable.point_off); } if (isCheck2) { point2.setBackgroundResource(R.drawable.point_on); } else { point2.setBackgroundResource(R.drawable.point_off); } if (isCheck3) { point3.setBackgroundResource(R.drawable.point_on); } else { point3.setBackgroundResource(R.drawable.point_off); } if (isCheck4) { point4.setBackgroundResource(R.drawable.point_on); } else { point4.setBackgroundResource(R.drawable.point_off); } }}
SharedPreferencesUtils.java
package Share_tool;import androID.content.Context;import androID.content.SharedPreferences;import androID.vIEw.VIEw;/**共享偏好类工具 */public class SharedPreferencesUtils { private static final String file_name="share_data"; private static SharedPreferences sp; /**保存数据的方法, * 由数据类型然后根据数据类型进行调用*/ public static voID saveBoolean(Context context, String key, boolean value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putBoolean(key, value).commit(); } public static voID saveString(Context context, String key, String value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putString(key, value).commit(); } public static voID saveInt(Context context, String key, int value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putInt(key, value).commit(); } public static voID saveBoolean(Context context, String key, String value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putString(key, value).commit(); } public static voID savefloat(Context context, String key, float value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putfloat(key, value).commit(); } public static voID saveLong(Context context, String key, Long value) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } sp.edit().putLong(key, value).commit(); } /**得到保存数据的方法, * 根据默认值得到保存的数据的具体类型, * 然后调用相对于的方法获取值*/ public static int getInt(Context context, String key,int defvalue) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } return sp.getInt(key, defvalue); } public static Boolean getBoolean(Context context, String key,Boolean defvalue) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } return sp.getBoolean(key, defvalue); } public static String getString(Context context, String key,String defvalue) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } return sp.getString(key, defvalue); } public static float getfloat(Context context, String key,float defvalue) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } return sp.getfloat(key, defvalue); } public static Long getLong(Context context, String key,Long defvalue) { if (sp == null){ sp = context.getSharedPreferences(file_name, 0); } return sp.getLong(key, defvalue); } /** * 清除所有数据 * @param context */ public static voID clear(Context context) { if(sp==null) sp = context.getSharedPreferences(file_name, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.clear().commit(); } /** * 清除指定数据 */ public static voID clearall(Context context,String key) { if(sp==null) sp = context.getSharedPreferences(file_name, Context.MODE_PRIVATE); SharedPreferences.Editor editor = sp.edit(); editor.remove(key); editor.commit(); }}
activity_splash.xml
<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID" xmlns:app="http://schemas.androID.com/apk/res-auto" xmlns:tools="http://schemas.androID.com/tools" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" tools:context=".Welcome"> <androIDx.vIEwpager.Widget.VIEwPager androID:ID="@+ID/pager_guIDe" androID:layout_wIDth="match_parent" androID:layout_height="match_parent" androID:overScrollMode="never"> </androIDx.vIEwpager.Widget.VIEwPager> <linearLayout androID:layout_wIDth="144dp" androID:layout_height="36dp" androID:layout_alignParentBottom="true" androID:layout_centerHorizontal="true" androID:layout_marginBottom="15dp" androID:gravity="center" androID:orIEntation="horizontal"> <ImageVIEw androID:ID="@+ID/point1" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1" /> <ImageVIEw androID:ID="@+ID/point2" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1"/> <ImageVIEw androID:ID="@+ID/point3" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1"/> <ImageVIEw androID:ID="@+ID/point4" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_weight="1" /> </linearLayout> <button androID:ID="@+ID/btn_guIDe" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:layout_alignParentBottom="true" androID:layout_centerHorizontal="true" androID:layout_marginBottom="60dp" androID:background="@null" androID:paddingleft="10dp" androID:paddingRight="10dp" androID:text="立即进入" androID:textAppearance="@style/TextAppearance.AppCompat.Body1" androID:textcolor="#CF8282" androID:textcolorHighlight="#1F7095" androID:textSize="36sp" androID:visibility="gone" /></relativeLayout> <!-- androID:layout_marginleft="10dp" androID:layout_marginRight="10dp"-->
总结 以上是内存溢出为你收集整理的Android开发引导页(仅出现一次)全部内容,希望文章能够帮你解决Android开发引导页(仅出现一次)所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)