从零开始制作点餐Android app(一)

1.2020/7/19开始
做个记录,学习Android
开发环境:
jdk:1.8
Android studio 4.0
一、首先,建立项目工程(按照下图操作)

二、建立好之后,会默认打开我们所创建的工程,我们按照如下操作
1、导入所需的jar文件

2、编写颜色资源文件

3、创建工程项目结构
在这里插入图片描述
三、首页设计
一)标题栏设计
1、新建标题布局文件

a:编写内容:
title_bar.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="50dp"
    android:background="@color/blue_color"
    >
    <ImageView
        android:layout_centerVertical="true"
        android:id="@+id/iv_back"
        android:clickable="true"
        android:layout_width="55dp"
        android:layout_height="55dp"
        android:background="@drawable/iv_back_selector"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/tv_title"
        android:text="首页"
        android:textColor="@android:color/white"
        android:textSize="25dp"
        android:layout_centerInParent="true"/>


</RelativeLayout>

2、创建点击事件选择器


iv_back_selector.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/iv_back" android:state_pressed="false"/>
    <item android:drawable="@drawable/iv_back_selected" android:state_pressed="true"/>
</selector>

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".activity.MainActivity">

    <include layout="@layout/title_bar"/>

</LinearLayout>

style.xml

<resources>
    <!-- Base application theme. -->
    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
    </style>

</resources>

自此首页标题栏布局完成。

二)内容页设计

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:orientation="vertical"
    tools:context=".activity.MainActivity">

    <include layout="@layout/title_bar"/>
<ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

    <ImageView android:layout_width="match_parent"
        android:layout_height="180dp"
        android:scaleType="fitXY"
        android:src="@drawable/banner"/>
    <com.example.orderproject.view.ShopListView
        android:id="@+id/iv_shop_list"
        android:layout_height="match_parent"
        android:layout_width="match_parent"
        />
    </LinearLayout>
    </ScrollView>

</LinearLayout>

mainactivity.java

package com.example.orderproject.activity;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;

import com.example.orderproject.R;

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

public class MainActivity extends AppCompatActivity {
private TextView tvTitle;
private ListView ivshopList;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initView();
    }

    private void initView() {
        tvTitle=findViewById(R.id.tv_title);
        ivshopList=findViewById(R.id.iv_shop_list);
        List<String> list=new ArrayList<>();
        for (int i=0;i<20;i++){
            list.add(i+"-"+i);
        }
        ArrayAdapter adapter=new ArrayAdapter(this,android.R.layout.simple_list_item_1,android.R.id.text1,list.toArray());
        ivshopList.setAdapter(adapter);
    }
}

新建view文件
在这里插入图片描述

ShopListView.java

package com.example.orderproject.view;

import android.content.Context;
import android.os.Message;
import android.util.AttributeSet;
import android.widget.ListView;

public class ShopListView extends ListView {
    public ShopListView(Context context) {
        super(context);
    }

    public ShopListView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    public ShopListView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        int heightSpec=MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >>2,MeasureSpec.AT_MOST);
        //VIEW的大小采用30位进行存储,那么我们应该给他30位的最大值,Int的最大值是32位
        super.onMeasure(widthMeasureSpec,heightSpec);
    }
}

效果图:
最终效果图
自此内容页布局结束

三)内容填充
创建工具文件。用于连接服务器并获取数据

装插件:gsonformat
gsonformat使用参考教程


装完之后要重新打开Android studio之后才会生效。

试下我们的接口地址:

复制接口全部内容。

然后再在我们的类下面去使用gsonformat。把我们上面的内容复制进去,就可以生成我们所需要的东西了。

这就是我们的生成的文件类了,有了这个东西就不需要自己去打对应的json的代码了。

package com.example.orderproject.bean;

import java.util.List;

public class ShopBean {


    /**
     * id : 1
     * shopName : 蛋糕房
     * saleNum : 996
     * offerPrice : 100
     * distributionCost : 5
     * welfare : 进店可获得一个香草冰淇淋
     * time : 配送约2-5小时
     * shopPic : http://192.168.31.135:3000/order/img/shop/shop1.png
     * shopNotice : 公告:下单后2-5小时送达!请耐心等候
     * foodList : [{"foodId":"1","foodName":"招牌丰收硕果12寸","taste":"水果、奶油、面包、鸡蛋","saleNum":"50","price":198,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food1.png"},{"foodId":"2","foodName":"玫瑰花创意蛋糕","taste":"玫瑰花、奶油、鸡蛋","saleNum":"100","price":148,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food2.png"},{"foodId":"3","foodName":"布朗熊与可妮","taste":"奶油、巧克力、果粒夹层","saleNum":"80","price":90,"count":0,"foodPic":"http://192.168.31.135:3000/order/img/food/food3.png"}]
     */

    private int id;
    private String shopName;
    private int saleNum;
    private int offerPrice;
    private int distributionCost;
    private String welfare;
    private String time;
    private String shopPic;
    private String shopNotice;
    private List<FoodListBean> foodList;

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public String getShopName() {
        return shopName;
    }

    public void setShopName(String shopName) {
        this.shopName = shopName;
    }

    public int getSaleNum() {
        return saleNum;
    }

    public void setSaleNum(int saleNum) {
        this.saleNum = saleNum;
    }

    public int getOfferPrice() {
        return offerPrice;
    }

    public void setOfferPrice(int offerPrice) {
        this.offerPrice = offerPrice;
    }

    public int getDistributionCost() {
        return distributionCost;
    }

    public void setDistributionCost(int distributionCost) {
        this.distributionCost = distributionCost;
    }

    public String getWelfare() {
        return welfare;
    }

    public void setWelfare(String welfare) {
        this.welfare = welfare;
    }

    public String getTime() {
        return time;
    }

    public void setTime(String time) {
        this.time = time;
    }

    public String getShopPic() {
        return shopPic;
    }

    public void setShopPic(String shopPic) {
        this.shopPic = shopPic;
    }

    public String getShopNotice() {
        return shopNotice;
    }

    public void setShopNotice(String shopNotice) {
        this.shopNotice = shopNotice;
    }

    public List<FoodListBean> getFoodList() {
        return foodList;
    }

    public void setFoodList(List<FoodListBean> foodList) {
        this.foodList = foodList;
    }

    public static class FoodListBean {
        /**
         * foodId : 1
         * foodName : 招牌丰收硕果12寸
         * taste : 水果、奶油、面包、鸡蛋
         * saleNum : 50
         * price : 198
         * count : 0
         * foodPic : http://192.168.31.135:3000/order/img/food/food1.png
         */

        private String foodId;
        private String foodName;
        private String taste;
        private String saleNum;
        private int price;
        private int count;
        private String foodPic;

        public String getFoodId() {
            return foodId;
        }

        public void setFoodId(String foodId) {
            this.foodId = foodId;
        }

        public String getFoodName() {
            return foodName;
        }

        public void setFoodName(String foodName) {
            this.foodName = foodName;
        }

        public String getTaste() {
            return taste;
        }

        public void setTaste(String taste) {
            this.taste = taste;
        }

        public String getSaleNum() {
            return saleNum;
        }

        public void setSaleNum(String saleNum) {
            this.saleNum = saleNum;
        }

        public int getPrice() {
            return price;
        }

        public void setPrice(int price) {
            this.price = price;
        }

        public int getCount() {
            return count;
        }

        public void setCount(int count) {
            this.count = count;
        }

        public String getFoodPic() {
            return foodPic;
        }

        public void setFoodPic(String foodPic) {
            this.foodPic = foodPic;
        }
    }
}

  • 15
    点赞
  • 131
    收藏
    觉得还不错? 一键收藏
  • 6
    评论
### 回答1: 开发一款Android点餐手机应用需要以下步骤: 1. 需求分析:确定应用的功能需求和用户需求,包括菜单展示、下单、支付、订单管理等。 2. UI设计:设计应用的界面,包括主页、菜单列表、购物车、订单页面等。 3. 数据库设计:设计应用所需的数据结构,包括菜单数据、订单数据等。 4. 后端开发:根据需求和数据库设计,开发后端接口,实现菜单的增删改查、订单的生成和查询等功能。 5. 前端开发:根据UI设计,开发应用的前端页面,实现菜单的展示、购物车的添加和删除、订单的提交等功能。 6. 测试和调试:对应用进行测试和调试,确保应用的稳定性和功能正常。 7. 发布和维护:将应用发布到应用商店,定期维护和更新应用。 以上是开发点餐手机应用的一般步骤,具体还需要根据实际情况进行调整。同时,开发手机应用需要掌握Java或Kotlin等语言,以及Android Studio开发工具。 ### 回答2: Android Studio是一个为Android平台开发应用程序的集成开发环境。对于一个点餐手机App开发Android Studio提供了丰富的工具和功能。 首先,我们可以利用Android Studio的UI设计工具来创建App的界面。通过拖拽控件和布局,我们可以轻松地设计出点餐界面,包括菜单列表、购物车和订单页面等。同时,Android Studio还提供了许多预设的样式和主题,可以快速美化界面,使其符合点餐App的风格和需求。 其次,我们可以使用Java或Kotlin这两种编程语言,在Android Studio中编写App的代码。我们可以利用这些语言的特性和语法来实现点餐App的各种功能,比如浏览菜单、添加菜品到购物车、下订单等。Android Studio还提供了强大的调试工具,方便我们检查和修复代码中的错误。 此外,Android Studio还提供了一系列用于测试和优化App的工具。我们可以使用Android模拟器来模拟不同的设备和版本,以确保我们的应用在各种环境下正常运行。同时,Android Studio还提供了性能分析器和调试器,可以帮助我们找出并解决App中的性能瓶颈和问题,提高用户体验。 最后,一旦我们完成了点餐App开发,我们可以使用Android Studio将应用打包成APK文件,方便用户下载和安装。Android Studio还可以帮助我们生成签名证书,以保证应用在发布和更新过程中的安全性。 综上所述,Android Studio是一个功能强大的开发工具,可以帮助我们开发高效、稳定、美观的点餐手机App。 ### 回答3: Android Studio是一款用于开发Android应用程序的集成开发环境(IDE)。利用Android Studio,可以轻松创建一个点餐手机app。 首先,使用Android Studio创建一个新项目。选择一个空白活动模板,并给项目命名。接下来,可以设置app的图标、启动画面和主题样式等。 然后,在主活动(Main Activity)中设计app的用户界面。可以添加各种UI组件,如文本框、按钮、下拉菜单和列表视图等,以及相关的事件处理。 接着,需要设计数据库模型用于存储菜品信息和订单数据。可以使用SQLite数据库来实现本地存储,也可以选择与云服务进行数据同步。 在代码中实现点餐功能。首先,需要查询数据库中的菜品列表并展示给用户。用户可以通过选择菜品和输入数量来加入购物车。同时,还可以实现搜索功能和价格排序等。 接下来,实现购物车功能。当用户点击结算按钮时,可以将购物车中的菜品生成订单并保存到数据库中。同时,还可以展示订单详情、计算总价和选择支付方式等。 除了基本功能外,还可以添加一些附加功能来提升用户体验。例如,添加用户注册和登录功能,实现用户评价和分享功能,以及实现在线支付和订单追踪等。 最后,进行测试和调试。可以使用模拟器或真机来运行app,并根据测试结果对代码进行修改和修复。同时,还可以进行性能优化和界面美化。 通过以上步骤,就可以在Android Studio中创建一个完善的点餐手机app开发完成后,可以将app发布到Google Play商店或其他分发渠道,供用户下载和使用。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 6
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值