Android自己仿美团做的外卖软件(巴哥外卖),新手进

先附上GitHub:https://github.com/LiuJingyingdev/Food

再附几张效果图:

主要用到的知识点,RecyclerView显示列表,ScollView,Materil Design的部分设计,导航栏用RadioGroup+Fragment,Intent传输数据,Selector(背景选择器),Shap样式等等。

下面是部分代码:

 

主活动:MainMenu

package com.example.food;

import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.DividerItemDecoration;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.ImageButton;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import java.io.EOFException;
import java.util.ArrayList;
import java.util.List;

import adapter.OderAdapter;
import adapter.Order;
import adapter.Person;
import adapter.PersonAdapter;
import adapter.Store;
import adapter.StoreAdapter;
import fragment.CarFragment;
import fragment.MenuFragment;
import fragment.PersonFragment;

//主菜单
public class MainMenu extends AppCompatActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener {


    private MenuFragment menuFragment;
    private CarFragment carFragment;
    private PersonFragment personFragment;
    private FragmentManager fragmentManager;


    private List<Store> storeList = new ArrayList<>();//首页商店的列表
    private List<Order> OrderList = new ArrayList<>();//订单列表
    private List<Person> personList = new ArrayList<>();//个人中心的列表

    RadioButton menu_Button;
    RadioButton car_Button;
    RadioButton person_Button;

    private Boolean a, b, c;
    private Boolean first;

    private RadioGroup chooseGroup;//单选按钮组,用来获取单选按钮响应事件
    private RadioButton defaultButton;//默认单选按钮


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            Window window = getWindow();
//设置修改状态栏
            window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
//设置状态栏的颜色,和你的app主题或者标题栏颜色设置一致就ok了
            window.setStatusBarColor(getResources().getColor(R.color.gray));
        }

        setContentView(R.layout.activity_main_menu);
        a = false;//首页碎片状态
        b = false;//订单碎片状态
        c = false;//个人中心碎片状态
        //初始化列表
        initSore();
        initOrder();
        iniPerson();


        menu_Button = (RadioButton) findViewById(R.id.radio_button1);
        car_Button = (RadioButton) findViewById(R.id.radio_button2);
        person_Button = (RadioButton) findViewById(R.id.radio_button3);
        changeImageSize(menu_Button, car_Button, person_Button);//改变底部单选按钮的大小


        chooseGroup = (RadioGroup) findViewById(R.id.choose_group);
        chooseGroup.setOnCheckedChangeListener(this);



        first = false;//判断事务是否第一次进行
        fragmentManager = getSupportFragmentManager();
        android.support.v4.app.FragmentTransaction myfragmentTransaction = fragmentManager.beginTransaction();
        if (menuFragment == null) {
            menuFragment = new MenuFragment();
            myfragmentTransaction.add(R.id.frame_layout, menuFragment);
        }
        if (carFragment == null) {
            carFragment = new CarFragment();
            myfragmentTransaction.add(R.id.frame_layout, carFragment);
        }
        if (personFragment == null) {
            personFragment = new PersonFragment();
            myfragmentTransaction.add(R.id.frame_layout, personFragment);
        }
        if (!first) {
            myfragmentTransaction.hide(carFragment);
            myfragmentTransaction.hide(personFragment);
            myfragmentTransaction.show(menuFragment);
            myfragmentTransaction.commit();
        }

       // menu_Button.setChecked(true);
        //让首页默认选中
        //defaultButton = (RadioButton) findViewById(R.id.radio_button1);


        //用来判断碎片的状态,是实例化了,还是空值


    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (i) {
            case R.id.radio_button1: {
                Select(1);
                break;
            }
            case R.id.radio_button2: {
                Select(2);
                break;
            }
            case R.id.radio_button3: {
                Select(3);
                break;
            }
        }
    }


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.imageButton1: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "美食");
                startActivity(intent);
                break;
            }
            case R.id.imageButton2: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "超市");
                startActivity(intent);
                break;
            }
            case R.id.imageButton3: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "生鲜");
                startActivity(intent);
                break;
            }
            case R.id.imageButton4: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "专送");
                startActivity(intent);
                break;
            }
            case R.id.imageButton5: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "代购");
                startActivity(intent);
                break;
            }
            case R.id.imageButton6: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "午餐");
                startActivity(intent);
                break;
            }
            case R.id.imageButton7: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "甜品");
                startActivity(intent);
                break;
            }
            case R.id.imageButton8: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "家常");
                startActivity(intent);
                break;
            }
            case R.id.imageButton9: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "小吃");
                startActivity(intent);
                break;
            }
            case R.id.imageButton10: {
                Intent intent = new Intent(MainMenu.this, MyClassify.class);
                intent.putExtra("class_type", "快餐");
                startActivity(intent);
                break;
            }
            default:
                break;
        }
    }

    private void Select(int i) {
//        android.support.v4.app.FragmentManager fragmentManager = getSupportFragmentManager();
//        android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        android.support.v4.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
        initFragment(fragmentTransaction);
        if (i == 1) {
            //用recyclerView陈列商店列表
            if (menuFragment == null) {
                menuFragment = new MenuFragment();
                fragmentTransaction.add(R.id.frame_layout, menuFragment);
                Log.d("TAG1", "加法减法就爱看放假啊垃圾分类卡机了开发");
            } else {
                if (!a) {

                    Log.d("TAG2", "奥卡福捡垃圾反垃圾发了简历发借记卡");
                    RecyclerView recyclerView1 = (RecyclerView) findViewById(R.id.recycler_view);
                    LinearLayoutManager layoutManager1 = new LinearLayoutManager(this);
                    layoutManager1.setOrientation(LinearLayoutManager.VERTICAL);
                    recyclerView1.setLayoutManager(layoutManager1);
                    //recyclerView1.addItemDecoration(new DividerItemDecoration(this,DividerItemDecoration.VERTICAL));
                    StoreAdapter adapter1 = new StoreAdapter(storeList);
                    recyclerView1.setAdapter(adapter1);
                    //处理recyclerview和scrollview滑动冲突
                    recyclerView1.setHasFixedSize(true);
                    recyclerView1.setNestedScrollingEnabled(false);

                    a = true;
                }

                Log.d("TAG3", ";类分类法放假啊洛夫克拉夫垃圾卡进了房间all结案率会计分录");


                //图片按钮
                ImageButton imageButton1;
                ImageButton imageButton2;
                ImageButton imageButton3;
                ImageButton imageButton4;
                ImageButton imageButton5;
                ImageButton imageButton6;
                ImageButton imageButton7;
                ImageButton imageButton8;
                ImageButton imageButton9;
                ImageButton imageButton10;

//                //首页显示的情况下,再获取首页中的控件
//                android.support.v4.app.FragmentManager manager;
//                MenuFragment fragment;
//
//                //下面是处理首页的ImagaButton的点击事件
//                /*获取manager*/
//                manager = this.getSupportFragmentManager();
//        /*通过findFragmentById获取Fragment*/
//                fragment = (MenuFragment) manager.findFragmentById(R.id.frame_layout);
//        /*通过fragment.getView()获取视图,然后在获取fragment中的button*/
                imageButton1 = (ImageButton) findViewById(R.id.imageButton1);
                imageButton2 = (ImageButton) findViewById(R.id.imageButton2);
                imageButton3 = (ImageButton) findViewById(R.id.imageButton3);
                imageButton4 = (ImageButton) findViewById(R.id.imageButton4);
                imageButton5 = (ImageButton) findViewById(R.id.imageButton5);
                imageButton6 = (ImageButton) findViewById(R.id.imageButton6);
                imageButton7 = (ImageButton) findViewById(R.id.imageButton7);
                imageButton8 = (ImageButton) findViewById(R.id.imageButton8);
                imageButton9 = (ImageButton) findViewById(R.id.imageButton9);
                imageButton10 = (ImageButton) findViewById(R.id.imageButton10);
                imageButton1.setOnClickListener(this);
                imageButton2.setOnClickListener(this);
                imageButton3.setOnClickListener(this);
                imageButton4.setOnClickListener(this);
                imageButton5.setOnClickListener(this);
                imageButton6.setOnClickListener(this);
                imageButton7.setOnClickListener(this);
                imageButton8.setOnClickListener(this);
                imageButton9.setOnClickListener(this);
                imageButton10.setOnClickListener(this);


                fragmentTransaction.show(menuFragment);//显示首页碎片


            }

        }
        if (i == 2) {
            if (carFragment == null) {
                carFragment = new CarFragment();
                fragmentTransaction.add(R.id.frame_layout, carFragment);
            } else {
                if (!b) {

                    RecyclerView recyclerView2 = (RecyclerView) findViewById(R.id.order_recylerview);
                    LinearLayoutManager layoutManager2 = new LinearLayoutManager(this);
                    recyclerView2.setLayoutManager(layoutManager2);
                    OderAdapter adapter2 = new OderAdapter(OrderList);
                    recyclerView2.setAdapter(adapter2);
                    b = true;
                }
                fragmentTransaction.show(carFragment);//显示订单碎片
            }


        }
        if (i == 3) {
            if (personFragment == null) {
                personFragment = new PersonFragment();
                fragmentTransaction.add(R.id.frame_layout, personFragment);
            } else {
                if (!c) {
                    RecyclerView recyclerView3 = (RecyclerView) findViewById(R.id.person_recyclerview);
                    LinearLayoutManager layoutManager3 = new LinearLayoutManager(this);
                    recyclerView3.setLayoutManager(layoutManager3);
                    PersonAdapter adapter3 = new PersonAdapter(personList);
                    recyclerView3.setAdapter(adapter3);
                    c = true;
                }
                fragmentTransaction.show(personFragment);//显示个人中心碎片
            }
        }
        fragmentTransaction.commit();//碎片提交事物
    }

    public void initFragment(android.support.v4.app.FragmentTransaction fragmentTransaction) {//初始化碎片
        if (menuFragment != null) {
            fragmentTransaction.hide(menuFragment);
        }
        if (carFragment != null) {
            fragmentTransaction.hide(carFragment);
        }
        if (personFragment != null) {
            fragmentTransaction.hide(personFragment);
        }
    }

    private void initSore() {
        Store a = new Store("原味坊", R.drawable.p1);
        storeList.add(a);
        Store b = new Store("大雄美食(玫瑰园店)", R.drawable.p2);
        storeList.add(b);
        Store c = new Store("陈生陈太", R.drawable.p3);
        storeList.add(c);
        Store d = new Store("非尝不可", R.drawable.p4);
        storeList.add(d);
        Store e = new Store("特工厨房", R.drawable.p5);
        storeList.add(e);
        Store f = new Store("先入为煮", R.drawable.p6);
        storeList.add(f);
        Store g = new Store("蜀园川菜馆", R.drawable.p7);
        storeList.add(g);
        Store h = new Store("私家屋", R.drawable.p8);
        storeList.add(h);
        Store i = new Store("Q堡堡", R.drawable.p9);
        storeList.add(i);
        Store j = new Store("沙县小吃", R.drawable.p10);
        storeList.add(j);
        Store k = new Store("德乐士(玫瑰园店)", R.drawable.p11);
        storeList.add(k);
        Store l = new Store("陈记关东煮", R.drawable.p12);
        storeList.add(l);
        Store m = new Store("正兴鸡扒", R.drawable.p13);
        storeList.add(m);
        Store n = new Store("叫了只炸鸡", R.drawable.p14);
        storeList.add(n);
        Store o = new Store("味食先", R.drawable.p15);
        storeList.add(o);
    }

    private void initOrder() {
        Order a = new Order("原味坊", R.drawable.p1);
        OrderList.add(a);
        Order b = new Order("大雄美食(玫瑰园店)", R.drawable.p2);
        OrderList.add(b);
        Order c = new Order("陈生陈太", R.drawable.p3);
        OrderList.add(c);
        Order d = new Order("非尝不可", R.drawable.p4);
        OrderList.add(d);
        Order e = new Order("特工厨房", R.drawable.p5);
        OrderList.add(e);
        Order f = new Order("先入为煮", R.drawable.p6);
        OrderList.add(f);
        Order g = new Order("蜀园川菜馆", R.drawable.p7);
        OrderList.add(g);
        Order h = new Order("私家屋", R.drawable.p8);
        OrderList.add(h);
        Order i = new Order("Q堡堡", R.drawable.p9);
        OrderList.add(i);
        Order j = new Order("沙县小吃", R.drawable.p10);
        OrderList.add(j);
        Order k = new Order("德乐士(玫瑰园店)", R.drawable.p11);
        OrderList.add(k);
        Order l = new Order("陈记关东煮", R.drawable.p12);
        OrderList.add(l);
        Order m = new Order("正兴鸡扒", R.drawable.p13);
        OrderList.add(m);
        Order n = new Order("叫了只炸鸡", R.drawable.p14);
        OrderList.add(n);
        Order o = new Order("味食先", R.drawable.p15);
        OrderList.add(o);
    }

    private void iniPerson() {
        Person a = new Person("巴哥红包");
        personList.add(a);
        Person b = new Person("商家代金券");
        personList.add(b);
        Person c = new Person("我的地址");
        personList.add(c);
        Person d = new Person("邀请有奖");
        personList.add(d);
        Person e = new Person("客服中心");
        personList.add(e);
        Person f = new Person("帮助和反馈");
        personList.add(f);
        Person g = new Person("协议和说明");
        personList.add(g);
    }


    private void changeImageSize(RadioButton menu_Button, RadioButton car_Button, RadioButton person_Button) {


        //定义底部标签图片大小
        Drawable drawableFirst = getResources().getDrawable(R.drawable.menu);
        drawableFirst.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
        menu_Button.setCompoundDrawables(null, drawableFirst, null, null);//只放上面

        Drawable drawableSearch = getResources().getDrawable(R.drawable.car);
        drawableSearch.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
        car_Button.setCompoundDrawables(null, drawableSearch, null, null);//只放上面

        Drawable drawableMe = getResources().getDrawable(R.drawable.person);
        drawableMe.setBounds(0, 0, 69, 69);//第一0是距左右边距离,第二0是距上下边距离,第三69长度,第四宽度
        person_Button.setCompoundDrawables(null, drawableMe, null, null);//只放上面
    }


}

底部导航栏布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">



                <RadioGroup
                    android:id="@+id/choose_group"
                    android:orientation="horizontal"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center">

                    <RadioButton
                        android:id="@+id/radio_button1"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="首页"
                        android:textColor="@drawable/menu_text"
                        android:layout_weight="1"
                        style="@style/radioStyle"
                        android:drawableTop="@drawable/menu"></RadioButton>
                    <RadioButton
                        android:id="@+id/radio_button2"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="订单"
                        android:textColor="@drawable/car_text"
                        android:layout_weight="1"
                        style="@style/radioStyle"
                        android:drawableTop="@drawable/car"></RadioButton>
                    <RadioButton
                        android:id="@+id/radio_button3"
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="我的"
                        android:textColor="@drawable/person_text"
                        android:layout_weight="1"
                        style="@style/radioStyle"
                        android:drawableTop="@drawable/person"></RadioButton>
                </RadioGroup>




</LinearLayout>

还有很多,你们可以看看,在这里就不贴了,喜欢点赞。

 

 

  • 6
    点赞
  • 36
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
司科仿美团O2O程序源码最新版+wap+微信版亲测完整版是一款基于PHP语言设计的团购网站源码。 司科出品,必属精品!司科公司多年网站建设经验,专业提供商城网站制作,团购网站建设,团购APP制作,商城客户端设计,微信营销系统等服务。 PC端功能介绍: 产品发布 发布以天为形式的商品项目(添加、删除、修改、编辑) 秒杀抢团项目 发布以秒为形式的商品项目 商户展示 一、商家有自己的简单的介绍页面,介绍信息和产品 二、商家可以自己的后台对商品券行验证消费。 商家专卖店展示系统 一、合作商家可以通过后台发布自己的展示商品和商家新闻,帮助树立商家企业形象,加强与商家的合作。 二、商家可以自己的后台对商品券行验证消费。 商家上传系统 商家可以自行上传产品,管理员审核,审核通过即可显示,审核不通过商家再修改。 商家结算系统 V1.0 超级商家结算系统,网站自动计算商家提成 超强团购商家店铺 团购商家有独立商家店铺展示,实用性强! 会员级别V1.2 根据会员消费情况等,可以自动升级级别 手机版微信支付 包括PC的扫描支付&微信公众号的微信支付 消费评价+评分功能 独家用户消费评价+评分功能,提升用户体验 城市代理商管理V1.0 每个城市产品可以由独立代理商后台管理 可修改商品时间 可对商品行修改结束时间,让操作更加方便、人性化。 支持商品退款 提供客户申请商品模式,让商品更加自由,让客户在商品中无后顾之忧,可对商品项目设置两种模式:支持 不支持。 支持快递商品 发布项目的时候,可选择优惠券或快递。 好友邀请 用户通过人人网、开心网、MSN/QQ等社交网络邀请好友注册购买。 邮件订阅 用户用来订阅本站每天商品项目信息,方便对自己感兴趣的商品项目及时下单购买。 短信订阅 用户输入手机号码订阅商品信息,可以收到每日最新商品的短信息。 本单答疑 展示在网站右侧,用户可通过答疑,向网站客服咨询,网站管理员在后台回复后显示内容。 常见问题 展示网站内的文字信息,比如:新手指南,入门教程以及常见问题等。 短信发券 用户购买时输入手机号码,购买成功后,可收到由商品网站统一发出的优惠券帐号和密码。 团券认证 用户消费商品券时,可以在此注销或查询团券有效期。团券注销后不可二次使用。 商家地图展示 通过后台设置商家的具体位置,方便消费型商品的客户查找 项目分类首页展示 首页分类不同的产品,不同楼层展示 多城市切换 商品产品可以分配不同的城市显示 在线客服QQ 通过客服qq,方便与网站浏览者及时沟通。 强大的在线分享 用户通过MSN 人人 网易 开心 豆瓣 百度 腾讯 飞信 新浪微博 QQ空间、等,快速分享给好朋友心怡的商品 网项目。 管理员等级及授权 总管理分配下属管理员,各自管理各自的项目 后台控制分类 自可以后台控制推荐产品,分类展示商品。 邮箱发送邮件 用户可以自己设置邮箱,群发邮件给用户 图片延时加载 采用图片延时加载,极大减少服务器带宽 快递单号批量上传 商家可以建立一个TXT文档,输入订单编号,快递单交给网站运营者,网站运营者在后台上传这个TXT文档, 系统批量给这些订单生成快递单号 每个项目设置自己独立的SEO 每个项目可以在后台设置自己独立的SEO,更利于网站被搜索引擎收录,让您的网站排名靠前。 整站生成静态页面 自动生成伪静态,可以增加网页访问速度及搜索引擎排名,提高网站的质量。 首页及内页广告位 通过后台的操作来发布首页及内页通栏相关的广告图片及图片链接从而及时发布重要信息和促销活动。 公告发布 统一发布公告,也可以按地区来发布相关的促销信息以及网站公告。 手机参与商品 通过手机上网参与商品。 购物车功能 方便用户一次性挑选多个商品行购买 用户购买选择快递 让用户在购买时自己选择城市和快递公司 到货评论功能 用户对已购买的商品发表评论。增加用户粘性,吸引其他浏览者 虚拟购买人数 项目可以设置虚拟购买人数,刺激用户消费 管理员操作日志 根据需求行后台管理员的权限分配 数据库的备份 根据需求自行在后台行数据备份 用户调查参与 发布小调查,直观了解用户产品需求 多件免邮功能 根据购买数量设置是否免去邮费 友情链接 通过后台设置文字链接及图片链接 网站统计 客户根据统计报表可以知道每天用户访问量IP、浏览量pv、地区、ip地址及来自那个网站等,可根据时间生成报表,从而为网络营销提供依据。 WAP端功能介绍: 城市切换 触屏版会根据打开的用户地区行自动城市更新,弹出提示,是否回到当前城市。 登陆注册 用户可以用QQ或者手机号码登陆触屏版行购物,减少繁琐的输入选项。 在线搜索 触屏版首页有搜索框,用户可以输入自己喜欢的产品关键字行查找购
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值