pos機(jī)沒(méi)有菜單

 新聞資訊2  |   2023-07-17 10:13  |  投稿人:pos機(jī)之家

網(wǎng)上有很多關(guān)于pos機(jī)沒(méi)有菜單,Recycleview模仿星巴克咖啡菜單物品列表的知識(shí),也有很多人為大家解答關(guān)于pos機(jī)沒(méi)有菜單的問(wèn)題,今天pos機(jī)之家(www.sengkou.cn)為大家整理了關(guān)于這方面的知識(shí),讓我們一起來(lái)看下吧!

本文目錄一覽:

1、pos機(jī)沒(méi)有菜單

pos機(jī)沒(méi)有菜單

前言

RecycleView的使用

RecyclerView是Google在API 21下support.V7包里的控件,用來(lái)替代ListView。

官網(wǎng)對(duì)RecycleView的描述為:A flexible view for providing a limited window into a large data set。

一、使用RecycleView的前提條件

想使用RecycleView,一定要在build.gradle中引入compile \'com.android.support:recyclerview-v7:24.0.0\'依賴。

二、使用RecycleView的優(yōu)缺點(diǎn)

優(yōu)點(diǎn):

RecycleView強(qiáng)制封裝ViewHolder相當(dāng)輕松的設(shè)置布局管理器以控制Item的布局方式,橫向、豎向以及瀑布流方式可設(shè)置Item操作的動(dòng)畫(huà),刪除或者添加等通過(guò)ItemDecoration,控制Item間的間隔,可自己繪制

缺點(diǎn):

需要自己實(shí)現(xiàn)OnItemClickListener點(diǎn)擊事件(這么實(shí)用的需求,Google竟然讓我們自己實(shí)現(xiàn)...)

不過(guò)我認(rèn)為Recycleview的ItemDecoration非常強(qiáng)大,你可以使用它實(shí)現(xiàn)listview的分割線,懸浮窗,甚至一些非常炫的動(dòng)畫(huà)~

效果圖

ItemDecorationonDraw():和普通view的onDraw差不多,就是繪制在畫(huà)布上繪制東西。onDrawOver():就是基于onDraw上再次繪制點(diǎn)東西,over的意思。getItemOffsets():Recycleview可以通過(guò)他拿到每一個(gè)item的間距,所以只需要控制這個(gè)間距,并在間距里利用onDrawOver再繪制你想繪制的東西。

實(shí)現(xiàn)這個(gè)的思路,我們只需要在指定的的行數(shù)通過(guò)getItemOffsets預(yù)留出我們要空出的高度,然后通過(guò)onDrawOver繪制出你所希望的view即可。1.手動(dòng)構(gòu)造數(shù)據(jù)格式,如下,返回list

Goods goods1 = new Goods("人氣TOP", "正果拿鐵1", "Y27", "默認(rèn):大/單糖/熱");Goods goods99 = new Goods("人氣TOP", "正果拿鐵2", "Y27", "默認(rèn):大/單糖/熱");Goods goods91 = new Goods("人氣TOP", "正果拿鐵3", "Y27", "默認(rèn):大/單糖/熱");Goods goods2 = new Goods("大師咖啡", "拿鐵", "Y27", "默認(rèn):大/單糖/熱");Goods goods3 = new Goods("大師咖啡", "香草拿鐵", "Y24", "默認(rèn):大/單糖/熱");Goods goods4 = new Goods("大師咖啡", "焦糖拿鐵", "Y26", "默認(rèn):大/半糖/熱");List<Goods> list = new ArrayList<>();2.書(shū)寫(xiě)自己的ItemDecorationgetItemOffsets預(yù)留空間,只需要在每個(gè)數(shù)組的第一個(gè)數(shù)據(jù)預(yù)留一個(gè)高度,比如第一個(gè)人氣TOP,第一個(gè)大師咖啡。

第一個(gè)必須預(yù)留,當(dāng)前位置的name和前一個(gè)不相等則為預(yù)留空間 @Overridepublic boolean isParent(int position) { if (position == 0) return true; if (!list.get(position).getType().equals(list.get(position - 1).getType())) return true; return false;}//是否為當(dāng)前最后一個(gè)itemprotected boolean lastOneInGroup(int position) { String parentName = mDecorListener.parentName(position); String nextGroupName; try { nextGroupName = mDecorListener.parentName(position + 1); } catch (Exception e) { nextGroupName = null; } if (nextGroupName == null) { return false; } return !TextUtils.equals(parentName, nextGroupName);//與下一行的name不一樣說(shuō)明當(dāng)前是最后一行 }由上isParent判斷是第一個(gè)的返回你要預(yù)留的高度大小,否則為不需要空間0 @Override public void getItemOffsets(rect outRect, View view, RecyclerView parent, RecyclerView.State state) { super.getItemOffsets(outRect, view, parent, state); int position = parent.getChildAdapterPosition(view); if (parent.getLayoutManager() instanceof LinearLayoutManager && mDecorListener.isParent(position)) { outRect.top = decorationHeight; return; } outRect.top = 0; }在預(yù)留的空間上畫(huà)上你的view

@Override public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) { super.onDrawOver(c, parent, state); final int itemCount = state.getItemCount(); 全部item的數(shù)量 final int childCount = parent.getChildCount(); 可看見(jiàn)的排除懸停的分割線的個(gè)數(shù) final int left = parent.getPaddingLeft(); final int right = parent.getwidth="360px",height="auto" />

Group if (mDecorListener.isParent(position) || i == 0) {//中第一個(gè)位置和可見(jiàn)的第一個(gè)才有這個(gè)懸停 //繪制懸浮, int bottom = Math.max(decorationHeight, (childView.getTop() + parent.getPaddingTop())); //決定當(dāng)前頂部第一個(gè)懸浮Group的bottom,拿到item高度和規(guī)定高度對(duì)比,只是選擇一個(gè)合適的高度定義分割線 if (position + 1 < itemCount) { //下一組的第一個(gè)View接近頭部 int viewBottom = childView.getBottom(); if (lastOneInGroup(position) && viewBottom < bottom) { bottom = viewBottom; //如果這個(gè)關(guān)掉,會(huì)覆蓋,頂上去效果失去,其實(shí)viewBottom逐漸變?yōu)?,這樣動(dòng)態(tài)的放置即將消失的懸浮攔,看上去就是下一個(gè)懸浮攔頂上來(lái)的 } } drawDecoration(c, position, left, right, bottom, parent); stickyHeaderPosArray.put(position, bottom); } } } private void drawDecoration(Canvas c, int position, int left, int right, int bottom, RecyclerView parent) { c.drawRect(left, bottom - decorationHeight, right, bottom, mGroutPaint); Paint.FontMetrics fm = mTextPaint.getFontMetrics(); //文字豎直居中顯示 float baseLine = bottom - (decorationHeight - (fm.bottom - fm.top)) / 2 - fm.bottom; //獲取文字寬度 mSideMargin = Math.abs(mSideMargin); c.drawText(mDecorListener.parentName(position), left + mSideMargin, baseLine, mTextPaint);//x軸,baseLine Rect rect = new Rect();//為了得到當(dāng)前text的屬性 mTextPaint.getTextBounds(mDecorListener.parentName(position), 0, mDecorListener.parentName(position).length(), rect); //繪制那條橫線 c.drawLine(left + mSideMargin * 2 + rect.width="360px",height="auto" />

讀者福利

最后,從畢業(yè)以后我在大廠工作多年,此前我指導(dǎo)過(guò)不少同行。很少跟大家一起探討,正好最近我花了一個(gè)多月的時(shí)間整理出來(lái)一份包括不限于高級(jí)UI、性能優(yōu)化、移動(dòng)架構(gòu)師、NDK、混合式開(kāi)發(fā)(ReactNative+Weex)微信小程序、Flutter等全方面的Android進(jìn)階實(shí)踐技術(shù),今天暫且開(kāi)放給有需要的人,讀到這的朋友還可以私信我免費(fèi)領(lǐng)取一份收集的Android核心知識(shí)體系文檔及更多Android進(jìn)階知識(shí)筆記和視頻資料。

資料免費(fèi)領(lǐng)取方式:轉(zhuǎn)發(fā)+轉(zhuǎn)發(fā)+轉(zhuǎn)發(fā)關(guān)注后,私信關(guān)鍵詞【面試】即可獲取免費(fèi)領(lǐng)取方式!

重要的事說(shuō)三遍,轉(zhuǎn)發(fā)+轉(zhuǎn)發(fā)+轉(zhuǎn)發(fā)!

更多知識(shí)分享

以上就是關(guān)于pos機(jī)沒(méi)有菜單,Recycleview模仿星巴克咖啡菜單物品列表的知識(shí),后面我們會(huì)繼續(xù)為大家整理關(guān)于pos機(jī)沒(méi)有菜單的知識(shí),希望能夠幫助到大家!

轉(zhuǎn)發(fā)請(qǐng)帶上網(wǎng)址:http://www.sengkou.cn/newsone/85388.html

你可能會(huì)喜歡:

版權(quán)聲明:本文內(nèi)容由互聯(lián)網(wǎng)用戶自發(fā)貢獻(xiàn),該文觀點(diǎn)僅代表作者本人。本站僅提供信息存儲(chǔ)空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如發(fā)現(xiàn)本站有涉嫌抄襲侵權(quán)/違法違規(guī)的內(nèi)容, 請(qǐng)發(fā)送郵件至 babsan@163.com 舉報(bào),一經(jīng)查實(shí),本站將立刻刪除。