【SSM+Android项目开发】【第一节】【基础页面切换】【项目实例】

【SSM+Android项目开发】【第一节】【基础页面切换】【项目实例】



前言

各位可以参考一下我们自己手机里面的APP,除去核心信息界面以外,还存在

  • 闪屏页:免除打开软件出现黑屏的尴尬
  • 广告页:部分软件用来恰饭部分,在我的项目是把它作为切换页面的中转站
  • 导航页:软件第一次启动才出现的部分,主要用来介绍软件的功能
  • 登陆页:dddd(懂得都懂)
  • 注册页:dddd

跳转逻辑
在这里插入图片描述


一、闪屏页-SplashActivity

  1. 逻辑讲述
    设置一个有背景图片的页面,使该页面经过几秒后自动切换到下一个页面

  2. 布局
    在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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"
    android:background="@drawable/bg_start"
    tools:context=".SplashActivity">
</androidx.constraintlayout.widget.ConstraintLayout>
  1. java代码部分
public class SplashActivity extends AppCompatActivity {

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

        //实机演示时,发现手机成功安装该软件后,直接在安装完成页面打开软件会出现关机现象
        //通过搜索得出的解释是点击打开按钮和点击图标启动时,Intent的参数传递的不一样,activity的启动方式不同,
        if ((getIntent().getFlags() & Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT) !=0){
            finish();
            return;
        }

        //启动线程,在该Activity停留2000毫秒后将组件跳转到广告页
        new Handler().postDelayed(new Runnable() {
            @Override
            public void run() {
                Intent intent=new Intent(getApplicationContext(),AdActivity.class);
                startActivity(intent);
                SplashActivity.this.finish();
            }
        },2000);
    }
}       
  1. 知识点:线程、intent(意图)
  2. 效果演示
    在这里插入图片描述

二、广告页-AdActivity

  1. 逻辑讲述
    设置一个有背景图片的页面,点击该背景图片会打开手机浏览器跳转到对应网页。并在背景之上设置了一个可点击的卡片视图,点击跳过会跳转到对应界面。

  2. 布局文件
    在这里插入图片描述

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".AdActivity">
    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <ImageButton
            android:id="@+id/ad_ib"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:src="@drawable/ad_ad1"
            android:padding="0dp"
            android:scaleType="fitXY"/>
        <androidx.cardview.widget.CardView
            android:id="@+id/ad_bt"
            android:layout_width="50dp"
            android:layout_height="50dp"
            app:cardCornerRadius="25dp"
            android:layout_gravity="right"
            android:layout_marginRight="25dp"
            android:layout_marginTop="25dp"
            app:cardBackgroundColor="@color/white_A50"
            android:clickable="true">
            <TextView
                android:id="@+id/ad_tv"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:textSize="10dp"
                android:text="跳过"
                android:textColor="@color/black"/>
        </androidx.cardview.widget.CardView>
    </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
  1. java代码部分
public class AdActivity extends AppCompatActivity {

    SharedPreferences sp;//安卓自带的轻量级型存储库,可以存储一些小型数据,我一般称为全局变量
    CardView bt;//可点击的卡片视图,倒计时结束后可点击跳过,跳转到下一个页面
    ImageButton ib;//图片按钮组件,设置了点击后跳转到对应网页
    TextView tv;//文本框组件,设置了用来显示倒计时
    MyCountDownTimer myCountDownTimer;//安卓自带倒计时类

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

        //启动全局变量
        sp=getSharedPreferences("sp",MODE_PRIVATE);
        //打开全局变量逻辑器
        SharedPreferences.Editor editor=sp.edit();

        //装配数据
        init();

        //初始化变量
        Intent intent = null;

        //初始化状态,调试软件
        //editor.putString("state","xxx").commit();

        //根据全局变量判断state,选择要跳转的Activity的意图
        switch (sp.getString("state","")){
            case "":
                //表示第一次启动未经历导航页,将预备启动导航页面
                intent=new Intent(getApplicationContext(),GuideActivity.class);
                break;
            case "login":
                //表示已经经历导航页但未登录,将预备启动登陆页面
                intent=new Intent(getApplicationContext(),LoginActivity.class);
                break;
            case "main":
                //表示已经登陆,将预备启动主界面
                intent=new Intent(getApplicationContext(),MainActivity.class);
                break;
            default:
                //表示出现异常情况,将对state值初始化并直接关闭程序,主要用于调试初始化软件
                Toast.makeText(getApplicationContext(),"参数出错,正在初始化退出",Toast.LENGTH_LONG).show();
                editor.putString("state","");
                editor.apply();
                finish();
        }

        
        //启动倒计时
        myCountDownTimer= new MyCountDownTimer(5000, 1000);
        myCountDownTimer.start();
        //设置按钮点击监听器,点击将跳转到预备activity
        Intent finalIntent = intent;
        bt.setOnClickListener(v -> {
            String message=tv.getText().toString().trim();
            //判断倒计时是否结束
            if (Objects.equals(message, "跳过")){
                //跳转页面
                startActivity(finalIntent);
                finish();
            }else{
                //显示吐丝
                Toast.makeText(this, "等待倒计时结束后点击跳过", Toast.LENGTH_SHORT).show();
            }
        });


        //设置图片按钮点击监听器,点击将跳转到对应的url
        ib.setOnClickListener(v -> {
            Uri uri = Uri.parse("https://war.qq.com/cp/a20200818xzz/index_p.shtml");
            Intent intent1 = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent1);
        });
    }

    //将视图组件映射到对象
    private void init() {
        bt = this.findViewById(R.id.ad_bt);
        ib = this.findViewById(R.id.ad_ib);
        tv = (TextView) findViewById(R.id.ad_tv);
    }


    //继承倒计时
    class MyCountDownTimer extends CountDownTimer {
        TextView tv=(TextView) findViewById(R.id.ad_tv);
        /**
         * @param millisInFuture    The number of millis in the future from the call
         *                          to {@link #start()} until the countdown is done and {@link #onFinish()}
         *                          is called.
         * @param countDownInterval The interval along the way to receive
         *                          {@link #onTick(long)} callbacks.
         */
        public MyCountDownTimer(long millisInFuture, long countDownInterval) {
            super(millisInFuture, countDownInterval);
        }

        //设置倒计时进行中的文本框内容
        @Override
        public void onTick(long millisUntilFinished) {
            tv.setText(millisUntilFinished/1000+"s");
        }

        //设置倒计时结束时的文本框内容
        @Override
        public void onFinish() {
            tv.setText("跳过");
        }
    }


    //销毁倒计时
    @Override
    protected void onDestroy() {
        if (myCountDownTimer != null) {
            myCountDownTimer.cancel();
        }
        super.onDestroy();
    }
}   
  1. 知识点:intent(意图)、CountDownTimer、SharedPreferences
  2. 效果演示

在这里插入图片描述


二、导航页-GuideActivity

  1. 逻辑讲述
    设置一个多面控件viewpage,在最后一页设置按钮跳转到其他活动

  2. 布局文件

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 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=".GuideActivity">
    <androidx.viewpager.widget.ViewPager
        android:id="@+id/guide_vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
  1. java代码部分
 public class GuideActivity extends AppCompatActivity {

    ViewPager vp;//设置多面控件viewpager
    ArrayList<View> arrayList;//视图数组
    View view1,view2,view3,view4;//对应的视图
    Button bt;//按钮控件,点击后将跳转到登录页
    SharedPreferences sp;//全局变量
    SharedPreferences.Editor editor;//全局变量逻辑器

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

        //将创建的对象对应组件
        init();

        //将视图列表装载到适配器
        vp.setAdapter(new ViewPager_1(getApplicationContext(),arrayList));

        //设置按钮点击监听器,点击按钮后跳转到登录页,并修改state值
        bt.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                editor.putString("state","login");
                editor.commit();
                Intent intent=new Intent(getApplicationContext(),LoginActivity.class);
                startActivity(intent);
                finish();
            }
        });

    }



    //将创建的对象对应组件
    private void init() {
        vp=this.findViewById(R.id.guide_vp);
        //将视图添加到数组中
        LayoutInflater inflater=getLayoutInflater();
        view1=inflater.inflate(R.layout.guide_view_1,null);
        view2=inflater.inflate(R.layout.guide_view_2,null);
        view3=inflater.inflate(R.layout.guide_view_3,null);
        view4=inflater.inflate(R.layout.guide_view_4,null);
        bt=view4.findViewById(R.id.guide_bt);
        arrayList=new ArrayList<>();
        arrayList.add(view1);
        arrayList.add(view2);
        arrayList.add(view3);
        arrayList.add(view4);

        //获取全局变量
        sp=getSharedPreferences("sp",MODE_PRIVATE);
        editor=sp.edit();
    }
}
  1. 知识点:ViewPager、LayoutInflater、Adapter
  2. 效果演示
    (补了广告页的点击图片跳转网页的效果)
    在这里插入图片描述
  3. 其他代码
    可以看到在导航页设置了一个ViewPager的适配器:
    vp.setAdapter(new ViewPager_1(getApplicationContext(),arrayList));
    并配备了四个xml视图:
    view1=inflater.inflate(R.layout.guide_view_1,null);
    view2=inflater.inflate(R.layout.guide_view_2,null);
    view3=inflater.inflate(R.layout.guide_view_3,null);
    view4=inflater.inflate(R.layout.guide_view_4,null);

ViewPager_1.java

public class ViewPager_1 extends PagerAdapter {


    Context context;
    ArrayList<View> list;

    public ViewPager_1(Context context, ArrayList<View> list) {
        this.context=context;
        this.list=list;
    }

    public int getCount() {
        return list.size();
    }

    public boolean isViewFromObject(View view,Object object) {
        return view==object;
    }

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

    public void destroyItem(ViewGroup container, int position,Object object) {
        container.removeView(list.get(position));
    }
}

guide_view_1.xml
在这里插入图片描述

<?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">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/bg_guide1"
        android:scaleType="fitXY"/>

</LinearLayout>

guide_view_2.xml
在这里插入图片描述

<?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">
    <ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/bg_guide2"
    android:scaleType="fitXY"/>

</LinearLayout>

guide_view_3.xml
在这里插入图片描述

<?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">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:src="@drawable/bg_guide3"
        android:scaleType="fitXY"/>

</LinearLayout>

guide_view_4.xml
在这里插入图片描述

<?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">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:background="@drawable/bg_guide4"
        android:scaleType="fitXY">

        <Button
            android:id="@+id/guide_bt"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginTop="300dp"
            android:background="@color/blackHalf"
            android:text="进入应用"
            android:textStyle="normal"
            android:textColor="@color/white" />

    </LinearLayout>
</LinearLayout>

由于该部分较为基础,这里项目描述的可能不是太详细,请见谅
最后,请大家在评论区批评指正

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
运行SSM(Spring+SpringMVC+MyBatis)与Vue项目的步骤如下: 1. 克隆或下载项目代码:在GitHub或其他代码托管平台上找到项目的代码仓库,将其克隆到本地,或者下载项目的压缩包并解压。 2. 启动后端SSM项目: a. 导入项目:使用IDE(如IntelliJ IDEA、Eclipse等)将后端SSM项目导入到工作空间中。 b. 配置数据库连接:在项目的配置文件(如`application.properties`或`application.yml`)中配置数据库连接相关信息,包括数据库地址、用户名、密码等。 c. 运行项目:执行项目的启动命令,通常是右键点击项目,选择“Run”或“Debug”来启动项目。 3. 启动前端Vue项目: a. 安装依赖:打开命令行终端,切换到前端项目的目录下,执行命令`npm install`安装项目所需的依赖。 b. 配置API地址:在前端项目的代码中,找到与后端API请求相关的配置文件或配置项,将其中的API地址修改为后端项目的地址。 c. 运行项目:执行命令`npm run serve`来启动前端项目。 4. 访问项目:等待后端和前端项目启动完毕后,打开浏览器,输入前端项目的访问地址(通常是`http://localhost:8080`或其他自定义端口号),即可访问运行中的SSM+Vue项目。 注意事项: - 确保本地已经安装了JDK、Maven、Node.js等所需的软件环境。 - 在运行前端项目之前,需要先安装项目所需的依赖,可以使用`npm install`命令来一次性安装所有依赖。 - 在修改后端配置文件或前端代码后,需要重启项目才能使修改生效。 - 在运行项目过程中,可能会遇到一些问题,如依赖安装失败、端口被占用等,需要根据具体情况进行排查和解决。
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值