日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關咨詢
選擇下列產(chǎn)品馬上在線溝通
服務時間:8:30-17:00
你可能遇到了下面的問題
關閉右側工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
鴻蒙HarmonyOS三方件開發(fā)指南-SwipeLayout側滑刪除

想了解更多內(nèi)容,請訪問:

創(chuàng)新互聯(lián)主要從事網(wǎng)站制作、成都網(wǎng)站建設、網(wǎng)頁設計、企業(yè)做網(wǎng)站、公司建網(wǎng)站等業(yè)務。立足成都服務巴楚,十余年網(wǎng)站建設經(jīng)驗,價格優(yōu)惠、服務專業(yè),歡迎來電咨詢建站服務:13518219792

和華為官方合作共建的鴻蒙技術社區(qū)

https://harmonyos.

1. SwipeLayout組件功能介紹

1.1.功能介紹:

SwipeLayout組件是一個側滑刪除組件。

1.2. 模擬器上運行效果:

2. SwipeLayout使用方法

2.1. 新建工程,增加組件Har包依賴

在應用模塊中添加HAR,只需要將SwipeLayout.har復制到entry\libs目錄下即可(由于build.gradle中已經(jīng)依賴的libs目錄下的*.har,因此不需要再做修改)。

2.2. 修改主頁面的布局文件

修改主頁面的布局文件ability_main.xml,將自定義的SwipeLayout添加到xml中,將初始狀態(tài)下展示的視圖添加到SwipeLayout作為index為0的子視圖:

 
 
 
 
  1.  
  2.     xmlns:ohos="http://schemas.huawei.com/res/ohos" 
  3.     ohos:id="$+id:total1" 
  4.     ohos:height="match_parent" 
  5.     ohos:width="match_parent" 
  6.     ohos:background_element="gray" 
  7.     ohos:orientation="vertical"> 
  8.     
  9.         ohos:id="$+id:sample2" 
  10.         ohos:height="80vp" 
  11.         ohos:width="match_parent" 
  12.         ohos:orientation="horizontal"> 
  13.         
  14.             ohos:id="$+id:bottom_layout1" 
  15.             ohos:height="match_parent" 
  16.             ohos:width="match_parent" 
  17.             ohos:background_element="white" 
  18.             ohos:multiple_lines="true" 
  19.             ohos:padding="10" 
  20.             ohos:text="要有最樸素的生活和最遙遠的夢想,即使明天天寒地凍,山高水遠,路遠馬亡。" 
  21.             ohos:text_alignment="left" 
  22.             ohos:text_size="14fp" 
  23.             ohos:visibility="visible"> 
  24.          
  25.         
  26.             ohos:id="$+id:bottom_wrapper1" 
  27.             ohos:height="match_parent" 
  28.             ohos:width="360px" 
  29.             ohos:background_element="#ddff00" 
  30.             ohos:orientation="horizontal" 
  31.             ohos:visibility="visible"> 
  32.             
  33.                 ohos:id="$+id:Texts1" 
  34.                 ohos:height="match_parent" 
  35.                 ohos:width="180px" 
  36.                 ohos:background_element="#7B1FA2" 
  37.                 ohos:left_padding="25" 
  38.                 ohos:right_padding="25" 
  39.                 ohos:text="收藏" 
  40.                 ohos:text_alignment="center" 
  41.                 ohos:text_color="#DC143C" 
  42.                 ohos:text_size="14fp" 
  43.                 ohos:visibility="visible" 
  44.                 /> 
  45.             
  46.                 ohos:id="$+id:texts2" 
  47.                 ohos:height="match_parent" 
  48.                 ohos:width="180px" 
  49.                 ohos:background_element="#C7C7CC" 
  50.                 ohos:left_padding="25" 
  51.                 ohos:right_padding="25" 
  52.                 ohos:text="刪除" 
  53.                 ohos:text_alignment="center" 
  54.                 ohos:text_color="#DC143C" 
  55.                 ohos:text_size="14fp" 
  56.                 ohos:visibility="visible" 
  57.                 /> 
  58.          
  59.         
  60.             ohos:id="$+id:images3" 
  61.             ohos:height="match_parent" 
  62.             ohos:width="match_parent" 
  63.             ohos:background_element="gray" 
  64.             ohos:image_src="$media:star" 
  65.             /> 
  66.         
  67.             ohos:id="$+id:bottom_fronts" 
  68.             ohos:height="match_parent" 
  69.             ohos:width="match_content" 
  70.             ohos:background_element="#ddff00" 
  71.             ohos:orientation="horizontal" 
  72.             ohos:visibility="visible"> 
  73.             
  74.                 ohos:id="$+id:images1" 
  75.                 ohos:height="match_parent" 
  76.                 ohos:width="180px" 
  77.                 ohos:background_element="green" 
  78.                 ohos:image_src="$media:star"/> 
  79.             
  80.                 ohos:id="$+id:images2" 
  81.                 ohos:height="match_parent" 
  82.                 ohos:width="180px" 
  83.                 ohos:background_element="red" 
  84.                 ohos:image_src="$media:trash"/> 
  85.          
  86.      
  87.     
  88.         ohos:id="$+id:images" 
  89.         ohos:height="match_content" 
  90.         ohos:width="match_content" 
  91.         ohos:background_element="green" 
  92.         ohos:image_src="$media:star" 
  93.         ohos:layout_alignment="horizontal_center" 
  94.         ohos:top_margin="100vp"/> 
  95.  

2.3. 初始化SwipeLayout

在MainAbilitySlince類的onStart函數(shù)中,增加如下代碼。

 
 
 
 
  1. SwipeLayout swipeLayout = (SwipeLayout) findComponentById(ResourceTable.Id_sample1); 
  2. DirectionalLayout right = (DirectionalLayout) findComponentById(ResourceTable.Id_bottom_wrapper); 
  3. //初始化 
  4. swipeLayout.initializeSwipe(); 
  5. DirectionalLayout left = (DirectionalLayout) findComponentById(ResourceTable.Id_bottom_front); 
  6. Image image3 = (Image) findComponentById(ResourceTable.Id_image3); 
  7. //將各個方向拖拽時對應展示的視圖添加到swipeLayout 
  8. swipeLayout.addDrag(SwipeLayout.DragEdge.Left, right); 
  9. swipeLayout.addDrag(SwipeLayout.DragEdge.Right, left); 
  10. swipeLayout.addDrag(SwipeLayout.DragEdge.Bottom, image3); 

3. SwipeLayout開發(fā)實現(xiàn)

3.1. 新建一個Module

新建一個Module,類型選擇HarmonyOS Library,模塊名為SwipeLayout,如圖

3.2. 新建一個SwipeLayout類

新建一個SwipeLayout類,繼承自PositionLayout類

SwipeLayout的主要流程:

1. 首先通過xml的構造方法,為SwipeLayout添加拖拽監(jiān)聽;

2. 將LinkedHashMap

3. 通過public void addDrag(DragEdge dragEdge, Component child) 方法將可拖拽的方向和對應展示的視圖添加到mDragEdges,并設置其初始的ContentPosition;

 
 
 
 
  1. public void addDrag(DragEdge dragEdge, Component child) { 
  2.     mDragEdges.put(dragEdge, child); 
  3.     switch (dragEdge) { 
  4.         case Left: 
  5.             child.setContentPosition(getWidth(), 0); 
  6.             break; 
  7.         case Right: 
  8.             HiLog.info(label, "Log_addDrag" + child.getHeight()); 
  9.             child.setContentPosition(-child.getWidth(), 0); 
  10.             break; 
  11.         case Top: 
  12.             child.setContentPosition(0, getHeight()); 
  13.             break; 
  14.         case Bottom: 
  15.             child.setContentPosition(0, -child.getHeight()); 
  16.             break; 
  17.     } 
  18.     child.setVisibility(INVISIBLE); 
  19.     addComponent(child, 0); 

4.在拖拽動作的監(jiān)聽回調方法中完成對視圖的更新

A.在update回調中設置打開和關閉的邊界以及邊界內(nèi)的位置刷新

 
 
 
 
  1. if (getSurfaceView().getContentPositionY() + dragInfo.yOffset <= 0) { 
  2.     close(); 
  3. } else if (getSurfaceView().getContentPositionY() + dragInfo.yOffset >= getHeight()) { 
  4.     open(); 
  5. } else { 
  6.     getSurfaceView().setContentPositionY(getSurfaceView().getContentPositionY() + (float) dragInfo.yOffset); 
  7.     getCurrentBottomView().setContentPositionY(getCurrentBottomView().getContentPositionY() + (float) dragInfo.yOffset); 

B.在end中判斷滑動的距離,如果大于設定的滑動距離則直接將控件展開或者關閉

 
 
 
 
  1. if (isCloseBeforeDrag && mDragDistanceY < 0) { 
  2.     if (Math.abs(mDragDistanceY) >= mWillOpenPercentAfterClose * getBottomViewHeight()) { 
  3.         open(); 
  4.     } else { 
  5.         close(); 
  6.     } 
  7. if (!isCloseBeforeDrag && mDragDistanceY > 0) { 
  8.     if (Math.abs(mDragDistanceY) >= mWillOpenPercentAfterClose * getBottomViewHeight()) { 
  9.         close(); 
  10.     } else { 
  11.         open(); 
  12.     } 

3.3. 編譯HAR包

利用Gradle可以將HarmonyOS Library庫模塊構建為HAR包,構建HAR包的方法如下:

在Gradle構建任務中,雙擊PackageDebugHar或PackageReleaseHar任務,構建Debug類型或Release類型的HAR。

待構建任務完成后,可以loadingview> bulid > outputs > har目錄中,獲取生成的HAR包。

項目源代碼地址:https://github.com/isoftstone-dev/SwipeBackLayout

歡迎交流:HWIS-HOS@isoftstone.com

想了解更多內(nèi)容,請訪問:

和華為官方合作共建的鴻蒙技術社區(qū)

https://harmonyos.


當前名稱:鴻蒙HarmonyOS三方件開發(fā)指南-SwipeLayout側滑刪除
標題網(wǎng)址:http://www.5511xx.com/article/coghpse.html