首頁(yè)的設(shè)計(jì)很簡(jiǎn)單小程序訂餐平臺(tái),最內(nèi)層是強(qiáng)化版,只包含一個(gè)下拉刷新布局,之后嵌套一個(gè)滾動(dòng)控件,大功告成。代碼如下:
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto">
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
androidx.coordinatorlayout.widget.CoordinatorLayout>
java文件或許就是展示列表:1、創(chuàng)建數(shù)據(jù)源2、創(chuàng)建適配器,同時(shí)加載數(shù)據(jù)源3、設(shè)置適配器。
之后給下拉刷新布局設(shè)置個(gè)竊聽器,之后通知適配器更新數(shù)據(jù)源。
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_home, container, false);
// 創(chuàng)建數(shù)據(jù)源
initFoods();
RecyclerView recyclerView = view.findViewById(R.id.recycler_view);
GridLayoutManager gridLayoutManager = new GridLayoutManager(getContext(),2);
recyclerView.setLayoutManager(gridLayoutManager);
// 創(chuàng)建適配器,同時(shí)加載數(shù)據(jù)源
foodAdapter = new FoodAdapter(foodList);
// 設(shè)置適配器
recyclerView.setAdapter(foodAdapter);
swipeRefresh = view.findViewById(R.id.swipe_refresh);
swipeRefresh.setColorSchemeResources(R.color.design_default_color_primary);
swipeRefresh.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
@Override
public void onRefresh() {
refreshFoods();
}
});
return view;
}
4.4購(gòu)物車
購(gòu)物車的也十分簡(jiǎn)單,須要注意每位布局/控件的和屬性。
最內(nèi)層,真的太好用了,強(qiáng)烈推薦!和首頁(yè)布局惟一不同的就是上面還包了一個(gè)漂浮按鍵。
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.google.android.material.floatingactionbutton.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|end"
android:layout_marginBottom="80dp"
android:layout_marginRight="30dp"
android:src="@mipmap/nav_task"
app:maxImageSize="50dp"
android:backgroundTint="@color/Azure"
android:elevation="8dp"/>
<androidx.swiperefreshlayout.widget.SwipeRefreshLayout
android:id="@+id/swipe_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
androidx.swiperefreshlayout.widget.SwipeRefreshLayout>
androidx.coordinatorlayout.widget.CoordinatorLayout>
java文件或許就是獲取控件實(shí)例,之后設(shè)置竊聽器,這兒我們就展示漂浮按鍵的竊聽器吧,備考下的標(biāo)準(zhǔn)用法,作為模板。
// 訂單提交
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
AlertDialog alertDialog = new AlertDialog.Builder(view.getContext())
.setTitle("提示")
.setIcon(R.drawable.ic_order)
.setMessage("您確定要提交訂單嗎?")
.setPositiveButton("確定", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
cartDao.openDB();
cartDao.commitOrder();
cartDao.clearCart();
cartDao.closeDB();
Toast.makeText(getContext(), "下單成功!請(qǐng)下拉刷新頁(yè)面~", Toast.LENGTH_SHORT).show();
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
Toast.makeText(getContext(), "訂單已取消", Toast.LENGTH_SHORT).show();
}
})
.show();
}
});
4.5我的
布局就很中規(guī)中矩了,最常見的布局和控件,不再贅言了,只要花時(shí)間都能設(shè)計(jì)好的布局。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/Azure"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/circle_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="20dp"
app:civ_border_width="2dp"
android:src="@mipmap/nav_icon"
app:civ_border_color="@color/CadetBlue"
android:layout_marginBottom="20dp"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="@drawable/ic_chihuo"/>
<View
style="@style/PersonLineStyle"
android:layout_marginTop="10dp"
android:background="@color/white"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/LightCyan">
<ImageView
style="@style/PersonImageStyle"
android:src="@drawable/ic_person"/>
<TextView
android:id="@+id/person"
style="@style/PersonTvStyle"
android:text="@string/person" />
LinearLayout>
<View
style="@style/PersonLineStyle"
android:background="@color/white"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/LightCyan">
<ImageView
style="@style/PersonImageStyle"
android:src="@drawable/ic_order"/>
<TextView
android:id="@+id/order"
style="@style/PersonTvStyle"
android:text="@string/order" />
LinearLayout>
<View
style="@style/PersonLineStyle"
android:background="@color/white"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/LightCyan">
<ImageView
style="@style/PersonImageStyle"
android:src="@drawable/ic_share"/>
<TextView
android:id="@+id/share"
style="@style/PersonTvStyle"
android:text="@string/share" />
LinearLayout>
<View
style="@style/PersonLineStyle"
android:background="@color/white"/>
<androidx.cardview.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="6dp"
android:elevation="5dp">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/ic_more"/>
androidx.cardview.widget.CardView>
LinearLayout>
java代碼就是獲取控件實(shí)例,之后綁定竊聽器,最后展示下滑動(dòng)菜單欄選中風(fēng)波的竊聽器,也就是關(guān)掉側(cè)滑菜單。
// 菜單項(xiàng)選中事件的監(jiān)聽器
navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() {
@Override
public boolean onNavigationItemSelected(MenuItem item) {
drawerLayout.closeDrawers();
return true;
}
});
4.6滑動(dòng)菜單
是中提供的一個(gè)控件,致使滑動(dòng)菜單界面的實(shí)現(xiàn)顯得十分簡(jiǎn)單。使用之前,還須要打算兩個(gè)東西:menu和,menu是拿來(lái)在中顯示具體菜單項(xiàng)的,則是拿來(lái)在中顯示頸部布局的。
res/menu/.xml就是具體的菜單項(xiàng),
免責(zé)聲明:部分文章信息來(lái)源于網(wǎng)絡(luò)以及網(wǎng)友投稿,本站只負(fù)責(zé)對(duì)文章進(jìn)行整理、排版、編輯,出于傳遞更多信息之目的,并不意味著贊同其觀點(diǎn)或證實(shí)其內(nèi)容的真實(shí)性,如本站文章和轉(zhuǎn)稿涉及版權(quán)等問題,請(qǐng)作者在及時(shí)聯(lián)系本站,我們會(huì)盡快為您處理。
- 鄉(xiāng)村小鎮(zhèn)外賣騎手的故事:互聯(lián)網(wǎng)快車下的新生活與兼職收入
- 掃碼點(diǎn)餐成電子時(shí)代新常態(tài),消費(fèi)者體驗(yàn)與隱私保護(hù)需平衡
- 了解外賣平臺(tái)發(fā)展前景后,作者發(fā)表看法,技術(shù)推動(dòng)平臺(tái)升級(jí)
- 同城活動(dòng)報(bào)名系統(tǒng):連接你我,開啟無(wú)限可能
- 校園外賣_配送系統(tǒng):打造本地智慧生活服務(wù)的專業(yè) SaaS 系統(tǒng)
- 外賣小程序開發(fā)攻略:從需求明確到平臺(tái)選擇,全方位指南
熱門資訊
- 美團(tuán)外賣的抽成規(guī)則 餓了么抽點(diǎn)比例是多少
- 外賣好評(píng)30字有哪些 常見的外賣評(píng)語(yǔ)大全
- 木屋燒烤價(jià)目表一覽 微信外賣訂餐系統(tǒng)推薦
- 海底撈排隊(duì)取號(hào)微信是多少 海底撈是怎么預(yù)約排隊(duì)
- 如何通過(guò)微信掃碼支付找到支付人微信號(hào)?看這里!
- 胡桃里消費(fèi)人均大概是多少錢 二維碼掃碼點(diǎn)餐系統(tǒng)哪個(gè)好用
- 美團(tuán)外賣怎么點(diǎn)兩份?步驟及注意事項(xiàng)!!
- 肯德基優(yōu)惠券怎么獲得 肯德基微信外賣怎么點(diǎn)
- 連鎖收銀系統(tǒng)對(duì)連鎖門店運(yùn)營(yíng)會(huì)有怎么樣的影響?
- 微信公眾號(hào)點(diǎn)餐是怎么實(shí)現(xiàn) 餐飲商家怎么制作外賣訂餐系統(tǒng)