自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

安卓VS鴻蒙第三方件切換寶典 V2.0(第一部分)

系統(tǒng)
文章由鴻蒙社區(qū)產(chǎn)出,想要了解更多內(nèi)容請前往:51CTO和華為官方戰(zhàn)略合作共建的鴻蒙技術(shù)社區(qū)https://harmonyos.51cto.com

[[401683]]

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

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

https://harmonyos.51cto.com

眾所周知,安卓應(yīng)用開發(fā)經(jīng)過這么多年的發(fā)展相對成熟和穩(wěn)定,鴻蒙OS作為后來者兼容一個成熟的開發(fā)體系會節(jié)省很多推廣和開發(fā)成本。但在實際開發(fā)中,代碼層面仍然有很多細節(jié)上的差異,會給初次開發(fā)人員造成困擾。

本寶典旨在匯總實際開發(fā)中第三方件接入時的代碼差異,以期幫助開發(fā)人員更好的進行開發(fā)作業(yè),由于目前接觸的開發(fā)類型有限,所匯總的內(nèi)容多少會有疏漏,后期我們會進一步完善和補全。

歡迎關(guān)注我們以及我們的專欄,方便您及時獲得相關(guān)內(nèi)容的更新。

消息&多線程

1.設(shè)置線程級別

安卓:

  1. android.os.Process.setThreadPriority(android.os.Process.THREAD_PRIORITY_XXXXX); 

鴻蒙:

  1. ProcessManager.setThreadPriority(Thread.xxx); 

2.判斷是否是主線程

安卓:

  1. Looper.getMainLooper().getThread() == Thread.currentThread() 

鴻蒙:

  1. EventRunner.getMainEventRunner().isCurrentRunnerThread(); 

3.取消任務(wù)操作

安卓:

  1. task.cancel(true); 

鴻蒙:

  1. task.revoke(); 

布局&組件

1.展示一段時間的提示信息彈框

安卓:

  1. Toast makeText(Context context,String msg,int duration).show(); 

鴻蒙:

  1. new ToastDialog(Context context).setText(String msg).show(); 

2.給控件設(shè)置它的左中右上的圖片

安卓

1.代碼中:

  1. Drawable dwLeft = getResources().getDrawable(R.mipmap.ic_launcher); 
  2. dwLeft.setBounds(0, 0, dwLeft.getMinimumWidth(), dwLeft.getMinimumHeight()); 
  3. View.setCompoundDrawables(dwLeft, nullnullnull); 

 2.布局中:

  1. android:drawableLeft=“@mipmap/ic_launcher” 
  2. android:drawableTop=“@mipmap/ic_launcher” 
  3. android:drawableRight=“@mipmap/ic_launcher” 
  4. android:drawableBottom=“@mipmap/ic_launcher” 

 鴻蒙:

1.代碼中:

  1. Resource resource = context.getResourceManager().getResource(ResourceTable.Media_select); 
  2. PixelMapElement element = new PixelMapElement(resource); 
  3. companent.setAroundElements(element,null,null,null); 

 2.布局中:

  1. ohos:element_left=“media:icon" ohos:element_right="media:icon"ohos:element  
  2. ​    
  3.  ight="media:icon” 
  4. ohos:element_top=“media:icon" ohos:element_bottom="media:icon"ohos:element  
  5. ​    
  6.  ottom="media:icon” 

 3.設(shè)置控件的多態(tài)化

安卓:

1.在布局中給控件設(shè)置:android:background=“@drawable/bt_login”

2.在xml中實現(xiàn)bt_login

  1. <?xml version=“1.0” encoding=“utf-8”?> 
  2. <selector xmlns:android=“http://schemas.android.com/apk/res/android”> 
  3. <!-- 控件點擊狀態(tài) --> 
  4. <item android:drawable=“@drawable/button_down” android:state_pressed=“true”></item> 
  5. <!-- 控件選中狀態(tài) --> 
  6. <item android:drawable=“@drawable/button_down” android:state_checked=“true”></item> 
  7.  
  8. </selector> 

 鴻蒙:

  1. Resource selectResource = context.getResourceManager().getResource(ResourceTable.Media_select); 
  2. Resource emptyResource = context.getResourceManager().getResource(ResourceTable.Media_unselect); 
  3. PixelMapElement selectElement = new PixelMapElement(selectResource); 
  4. PixelMapElement emptyElement = new PixelMapElement(emptyResource); 
  5. StateElement checkElement = new StateElement(); 
  6. checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_SELECTED}, selectElement); 
  7. checkElement.addState(new int[]{ComponentState.COMPONENT_STATE_EMPTY}, emptyElement); 
  8. component.setButtonElement(null); 
  9. component.setAroundElements(checkElement,null,null,null); 
  10. component.setSelected(true); 

 4.scrollView滾動

安卓:

  1. <ScrollView 
  2. android:layout_width=“match_parent” 
  3. android:layout_height=“match_parent”> 
  4. <LinearLayout 
  5. android:layout_width=“match_parent” 
  6. android:layout_height=“match_parent” 
  7. android:orientation=“vertical”> 
  8. </LinearLayout> 
  9. </ScrollView> 

 鴻蒙:

  1. <ScrollView 
  2. ohos:height=“match_content” 
  3. ohos:width=“match_parent” 
  4. <DirectionalLayout 
  5. ohos:height=“match_content” 
  6. ohos:width=“match_content” 
  7. ohos:orientation=“vertical”> 
  8. </DirectionalLayout> 
  9. </ScrollView> 

5.組件隱藏

安卓:

  1. 不可見: android:visibility=“invisible”; Java代碼:view.setVisibility(View.INVISIBLE); 隱藏: android:visibility=“gone”; Java代碼:view.setVisibility(View.GONE); 

鴻蒙:

  1. ohos:visibility=“hide”;comp.setVisibility(HIDE);ohos:visibility=“invisible”;comp.setVisibility(INVISIBLE) 

6.線性布局

安卓:

  1. LinearLayout 

鴻蒙:

  1. DirectionalLayout 

7.相對布局

安卓:

  1. RelativeLayout 

鴻蒙:

  1. DependentLayout 

8.幀布局

安卓:

  1. FrameLayout 

鴻蒙:

  1. StackLayout 

9.選項卡

安卓:

  1. TabLayout 

鴻蒙:

  1. TabList和Tab 

10.像素單位

安卓:

  1. dp 

鴻蒙:

  1. vp 

11.控件的對齊方式

安卓:

  1. Gravity.CENTER 

鴻蒙:

  1. LayoutAlignment.CENTER 

12.布局名稱及用法

安卓:

  1. RelativeLayout相對布局LinearLayout線性布局 

鴻蒙:

  1. DependentLayout相對布局 DirectionalLayout線性布局 

13.自定義布局

安卓:

  1. View inflate = 
  2. inflate(getContext(), R.layout.reg_view, this); 

 鴻蒙:

  1. component = LayoutScatter.getInstance(context).parse(com.istone.videocache.ResourceTable.Layout_ability_player,layout,false); 
  2. layout.addComponent(component, 0); 

 14.疊加布局,層級疊加

安卓:

  1. FrameLayout 

鴻蒙:

  1. StackLayout 

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

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

https://harmonyos.51cto.com

 

責(zé)任編輯:jianghua 來源: 鴻蒙社區(qū)
相關(guān)推薦

2021-03-03 14:17:40

鴻蒙HarmonyOS應(yīng)用開發(fā)

2019-04-10 11:06:54

前端HTMLCSS

2009-06-09 14:40:01

Javascript表單驗證

2009-06-11 15:25:39

Java隨機數(shù)

2009-06-12 10:34:40

Java Date

2025-01-22 08:01:53

2025-04-24 00:10:00

RAGAI人工智能

2013-07-08 15:45:04

Python

2009-06-12 10:08:05

StaticJava

2013-04-08 15:42:38

Backbone.js入門

2018-11-15 14:52:15

Spark數(shù)據(jù)機器學(xué)習(xí)

2013-09-24 10:07:19

Ruby項目

2011-08-03 10:12:38

2009-06-15 13:32:18

Java applet插件

2020-10-11 23:45:55

Python解釋器

2013-11-14 16:18:05

AndroidAudioAudioTrack

2020-10-10 14:36:10

Python

2018-12-19 09:03:04

物聯(lián)網(wǎng)供應(yīng)鏈物聯(lián)網(wǎng)應(yīng)用

2009-07-14 13:49:28

Swing組件AWT

2010-03-11 11:29:51

喬布斯
點贊
收藏

51CTO技術(shù)棧公眾號