Android项目(完整版+免费版)

Android项目(完整版+免费版),第1张

Android项目–关于星座相关的app 第一部分–界面效果图 页面一:(点击页面任意一个星座图标会显示相应的数据)
页面二:(可以更换男生或女生的星座,点击开始配对分析,能跳转相应的页面,并显示相应的数据分析)
页面三:(点击任意一个图标,跳转到相应的页面,展示这一年的运势数据)
页面四:(点击头像,能更换相应的星座,下一次登录,仍然会保存)
第二部分–图片素材

以下是百度网盘的链接:
链接:https://pan.baidu.com/s/1vbtOJNS-I2Lm1JXXxumZSg
提取码:1111

第三部分–部分代码

-XingZuoWeb(我的项目名称)—>app—>src—>main–>java–>com.example.xingzuoweb(自己创建的包名)–>MainActivity

package com.example.xingzuoweb;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.RadioGroup;
import com.example.xingzuoweb.bean.StarBean;
import com.example.xingzuoweb.luckfrag.LuckFragment;
import com.example.xingzuoweb.mefrag.MeFragment;
import com.example.xingzuoweb.parnterfrag.PartnerFragment;
import com.example.xingzuoweb.starfrag.StarFragment;
import com.example.xingzuoweb.utils.AssetsUtils;
import com.google.gson.Gson;
public class MainActivity extends AppCompatActivity implements RadioGroup.OnCheckedChangeListener{
   RadioGroup mainRg;
   //声明四个按钮对应的Fragment对象
    Fragment starFrag,luckFrag,partnerFrag,meFrag;
    private FragmentManager manager;
    private FragmentTransaction fragmentTransaction;
    private FragmentTransaction transaction;
    private FragmentTransaction fragmentTransaction1;
    private Object FragmentTransaction;
    private String jsonFromAssets;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mainRg = findViewById(R.id.main_rg);
        //设置监听器点击了哪个单选按钮
        mainRg.setOnCheckedChangeListener(this);
        //加载星座的数据
        StarBean infoBean = loadData();
        Bundle bundle = new Bundle();
        bundle.putSerializable("info",infoBean);
        //创建碎片对象
        starFrag = new StarFragment();
        starFrag.setArguments(bundle);
        luckFrag = new LuckFragment();
        luckFrag.setArguments(bundle);
        partnerFrag = new PartnerFragment();
        partnerFrag.setArguments(bundle);
        meFrag = new MeFragment();
        meFrag.setArguments(bundle);
        //将四个Fragment进行动态加载,一起加载到布局当中。
        addFragmentPage();
    }
    //读取assets下的文件
    private StarBean loadData() {
        String json = AssetsUtils.getJsonFromAssets(this, "xzcontent/xzcontent.json");
        Gson gson = new Gson();
        StarBean infoBean = gson.fromJson(json, StarBean.class);
        AssetsUtils.saveBitmapFromAssets(this,infoBean);
        return infoBean;
    }
    //将主页当中的碎片一起加载进入布局,有用的显示,暂时无用的隐藏。
    private void addFragmentPage() {
        //1.创建碎片管理者对象
        manager = getSupportFragmentManager();
        //2.创建碎片处理事务的对象
        FragmentTransaction transaction = manager.beginTransaction();
        //3.将四个Fragment统一的添加到布局当中
        transaction.add(R.id.main_layout_center,starFrag);
        transaction.add(R.id.main_layout_center,partnerFrag);
        transaction.add(R.id.main_layout_center,luckFrag);
        transaction.add(R.id.main_layout_center,meFrag);
        //4.隐藏后面的三个
        transaction.hide(partnerFrag);
        transaction.hide(luckFrag);
        transaction.hide(meFrag);
        //5.提交碎片改变后的事务
        transaction.commit();
    }
    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        FragmentTransaction transaction  = manager.beginTransaction();
        switch (checkedId){
            case R.id.main_rb_star:
                transaction.hide(partnerFrag);
                transaction.hide(luckFrag);
                transaction.hide(meFrag);
                transaction.show(starFrag);
                break;
            case R.id.main_rb_parnter:
                transaction.hide(starFrag);
                transaction.hide(luckFrag);
                transaction.hide(meFrag);
                transaction.show(partnerFrag);
                break;
            case R.id.main_rb_luck:
                transaction.hide(starFrag);
                transaction.hide(partnerFrag);
                transaction.hide(meFrag);
                transaction.show(luckFrag);
                break;
            case R.id.main_rb_me:
                transaction.hide(starFrag);
                transaction.hide(luckFrag);
                transaction.hide(partnerFrag);
                transaction.show(meFrag);
                break;
        }
        transaction.commit();
    }
}
com.example.xingzuoweb —> bean(自己创建的包)—> StarBean
package com.example.xingzuoweb.bean;

import java.io.Serializable;
import java.util.List;

public class StarBean implements Serializable {

    private List<StarinfoBean> starinfo;

    public List<StarinfoBean> getStarinfo() {
        return starinfo;
    }

    public void setStarinfo(List<StarinfoBean> starinfo) {
        this.starinfo = starinfo;
    }

    public static class StarinfoBean implements  Serializable{
        /**
         * logoname : baiyang
         * name : 白羊座
         * date : 3月21日-4月19日
         * td : 热情活力
         * gw : 第一宫
         * yy : 阳性
         * tz : 控制
         * zg : 火星
         * ys : 红色
         * zb : 红宝石
         * hm : 5
         * js : 铁
         * info : 白羊座有一种让人看见就觉得开心的感觉,因为总是看起来都是那么地热情、阳光、乐观、坚强,对朋友也慷概大方,性格直来直往,就是有点小脾气。白羊男有大男人主义的性格,而白羊女就是女汉子的形象。
         */

        private String logoname;
        private String name;
        private String date;
        private String td;
        private String gw;
        private String yy;
        private String tz;
        private String zg;
        private String ys;
        private String zb;
        private String hm;
        private String js;
        private String info;

        public String getLogoname() {
            return logoname;
        }

        public void setLogoname(String logoname) {
            this.logoname = logoname;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getDate() {
            return date;
        }

        public void setDate(String date) {
            this.date = date;
        }

        public String getTd() {
            return td;
        }

        public void setTd(String td) {
            this.td = td;
        }

        public String getGw() {
            return gw;
        }

        public void setGw(String gw) {
            this.gw = gw;
        }

        public String getYy() {
            return yy;
        }

        public void setYy(String yy) {
            this.yy = yy;
        }

        public String getTz() {
            return tz;
        }

        public void setTz(String tz) {
            this.tz = tz;
        }

        public String getZg() {
            return zg;
        }

        public void setZg(String zg) {
            this.zg = zg;
        }

        public String getYs() {
            return ys;
        }

        public void setYs(String ys) {
            this.ys = ys;
        }

        public String getZb() {
            return zb;
        }

        public void setZb(String zb) {
            this.zb = zb;
        }

        public String getHm() {
            return hm;
        }

        public void setHm(String hm) {
            this.hm = hm;
        }

        public String getJs() {
            return js;
        }

        public void setJs(String js) {
            this.js = js;
        }

        public String getInfo() {
            return info;
        }

        public void setInfo(String info) {
            this.info = info;
        }
    }
}

com.example.xingzuoweb —> home --> GuideActivity
package com.example.xingzuoweb.home;

import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;

import com.example.xingzuoweb.MainActivity;
import com.example.xingzuoweb.R;

import java.util.ArrayList;
import java.util.List;

public class GuideActivity extends AppCompatActivity {
    ViewPager guideVp;
    List<ImageView>mDatas;
    //存放三张图片的地址
    int resIds[] = {R.mipmap.loading1,R.mipmap.loading2,R.mipmap.loading3};
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_guide);
        guideVp = findViewById(R.id.guide_vp);
        mDatas = new ArrayList<>();
        initPager();
        //为第三个图片设置监听事件
        setListener();
    }

    private void setListener() {
        int size = mDatas.size();
        ImageView view = mDatas.get(size-1);
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(GuideActivity.this, MainActivity.class);
                startActivity(intent);
                finish();
            }
        });
    }

    private void initPager() {
        for (int i= 0;i<resIds.length;i++){
            ImageView imageView = new ImageView(this);
            imageView.setImageResource(resIds[i]);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
                    LinearLayout.LayoutParams.MATCH_PARENT);
            imageView.setLayoutParams(lp);
            mDatas.add(imageView);
        }
        GuideAdapter adapter = new GuideAdapter(mDatas);
        //设置适配器
        guideVp.setAdapter(adapter);
    }
}
com.example.xingzuoweb —> home --> GuideAdapter
package com.example.xingzuoweb.home;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.viewpager.widget.PagerAdapter;

import java.util.List;

public class GuideAdapter extends PagerAdapter {
    List<ImageView>mDatas;

    public GuideAdapter(List<ImageView> mDatas) {
        this.mDatas = mDatas;
    }

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

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

    @NonNull
    @Override
    public Object instantiateItem(@NonNull ViewGroup container, int position) {
        ImageView imageView = mDatas.get(position);
        container.addView(imageView);
        return imageView;
    }

    @Override
    public void destroyItem(@NonNull ViewGroup container, int position, @NonNull Object object) {
        ImageView imageView = mDatas.get(position);
        container.removeView(imageView);
    }
}

-com.example.xingzuoweb —> home —>WelcomeActivity

package com.example.xingzuoweb.home;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.widget.TextView;

import com.example.xingzuoweb.MainActivity;
import com.example.xingzuoweb.R;
public class WelcomeActivity extends AppCompatActivity {
    TextView tv;
    int count = 3;
    Handler handler = new Handler(){
        @Override
        public void handleMessage(@NonNull Message msg) {
           if (msg.what==1){
               count--;
               if (count==0){
                   //判断是否是第一次进入应用,如果是第一次进入此应用,跳转到引导页面
                   boolean isFirst = pref.getBoolean("isFirst",true);
                   Intent intent = new Intent();
                   if (isFirst){
                       intent.setClass(WelcomeActivity.this,GuideActivity.class);
                       SharedPreferences.Editor editor = pref.edit();
                       editor.putBoolean("isFirst",false);
                       editor.commit();
                   }else {
                       intent.setClass(WelcomeActivity.this,MainActivity.class);
                   }
                   startActivity(intent);
                   finish();
               }else {
                   tv.setText(String.valueOf(count));
                   handler.sendEmptyMessageDelayed(1,500);
               }
           }

        }
    };
    private SharedPreferences pref;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_welcome);
        tv = findViewById(R.id.welcome_tv);
        pref = getSharedPreferences("first_pref", MODE_PRIVATE);
        handler.sendEmptyMessageDelayed(1,500);
    }
}
第四部分–打包后的apk

以下是百度网盘的链接:
链接:https://pan.baidu.com/s/1u0iUk5glF11BRy-bYHub6g
提取码:1111
复制这段内容后打开百度网盘手机App, *** 作更方便哦

小伙伴们~ 由于代码量很大,需要完整的代码可以点击链接:XingZuoWeb.zip 进行下载哦~

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/992697.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-21
下一篇 2022-05-21

发表评论

登录后才能评论

评论列表(0条)

保存