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

安卓VS鴻蒙第三方件切換寶典 V1.0

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

[[384938]]

想了解更多內(nèi)容,請(qǐng)?jiān)L問:

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

https://harmonyos.51cto.com

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

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

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

※基礎(chǔ)功能

1.獲取屏幕分辨率

安卓:

  1. getWindowManager().getDefaultDisplay(); 

鴻蒙:

  1. Optional<Display>  
  2. display = DisplayManager.getInstance().getDefaultDisplay(this.getContext()); 
  3. Point pt = new Point(); 
  4. display.get().getSize(pt); 

2.隱藏標(biāo)題欄TitleBar

安卓:

鴻蒙:

confi.json中添加如下描述:

  1. ""metaData"":{ 
  2.        ""customizeData"":[ 
  3.            { 
  4.                ""name""""hwc-theme""
  5.                ""value""""androidhwext:style/Theme.Emui.NoTitleBar""
  6.                ""extra"":"""" 
  7.             } 
  8.        ] 
  9.    } 

3.獲取屏幕密度

安卓:

  1. Resources.getSystem().getDisplayMetrics().density 

鴻蒙:

  1. // 獲取屏幕密度 
  2. Optional<Display>  
  3. display = DisplayManager.getInstance().getDefaultDisplay(this.getContext());         
  4. DisplayAttributes displayAttributes = display.get().getAttributes(); 
  5. //displayAttributes.xDpi; 
  6. //displayAttributes.yDpi; 

4.獲取上下文

安卓:

  1. context 

鴻蒙:

  1. getContext() 

5.組件的父類

安卓:

  1. android.view.View; class ProgressBar extends View 

鴻蒙:

  1. class ProgressBar extends Component 

6.沉浸式顯示

安卓:

鴻蒙:

A:在config.json ability 中添加

  1. "metaData"": { 
  2.   ""customizeData"": [ 
  3.     { 
  4.       ""extra""""""
  5.       ""name""""hwc-theme""
  6.       ""value""""androidhwext:style/Theme.Emui.Light.NoTitleBar"" 
  7.     } 
  8.   ] 

B:在AbilitySlice的onStart函數(shù)內(nèi)增加如下代碼,注意要在setUIContent之前。

  1. getWindow().addFlags(WindowManager.LayoutConfig.MARK_TRANSLUCENT_STATUS); 

7.獲取運(yùn)行時(shí)權(quán)限

安卓:

  1. ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.CALL_PHONE}, 1) 

鴻蒙:

  1. requestPermissionsFromUser( 
  2.         new String[]{""ohos.permission.READ_MEDIA""""ohos.permission.WRITE_MEDIA""""ohos.permission.READ_USER_STORAGE""""ohos.permission.WRITE_USER_STORAGE"",}, 1); 

※布局&組件

1.頁面跳轉(zhuǎn)(顯示跳轉(zhuǎn))

安卓:

A.從A跳轉(zhuǎn)至B,沒有參數(shù),并且不接收返回值

  1. Intent intent = new Intent(); 
  2.     intent.setClass(A.this, B.class); 
  3.     startActivity(intent); 

B.從A跳轉(zhuǎn)至B,有參數(shù),不接收返回值

  1. Intent intent = new Intent(this, B.class); 
  2.  intent.putExtra(""name""""lily""); 
  3.  startActivity(intent); 

C.從A跳轉(zhuǎn)至B,有參數(shù),接收返回值

  1. Intent intent = new Intent(this, B.class); 
  2. intent.putExtra(""name""""lily""); 
  3. startActivityForResult(intent, 2); 

鴻蒙:

A.從A跳轉(zhuǎn)至B,沒有參數(shù),并且不接收返回值

  1. present(new BSlice(), new Intent()); 

B.從A跳轉(zhuǎn)至B,有參數(shù),不接收返回值

  1. Intent intent = new Intent(); 
  2.             Operation operation = new Intent.OperationBuilder() 
  3.                     .withDeviceId("""")                   .withBundleName(""com.test"")                    .withAbilityName(""com.test.BAbility""
  4.                     .build(); 
  5.             intent.setParam(""name"",""lily""); 
  6.             intent.setOperation(operation); 
  7.             startAbility(intent); 

C.從A跳轉(zhuǎn)至B,有參數(shù),接收返回值

  1. Intent intent = new Intent(); 
  2.             Operation operation = new Intent.OperationBuilder() 
  3.                     .withDeviceId("""")                    .withBundleName(""com.test"")                    .withAbilityName(""com.test.BAbility""
  4.                     .build(); 
  5.             intent.setParam(""name"",""lily""); 
  6.             intent.setOperation(operation); 
  7.             startAbilityForResult(intent,100); 

2.頁面跳轉(zhuǎn)(隱式跳轉(zhuǎn))

安卓:

A.配置

  1. <activity android:name="".B""
  2.             <intent-filter> 
  3.                 <action android:name=""com.hly.view.fling""/> 
  4.             </intent-filter> 
  5.         </activity> 

B.啟動(dòng)

  1. Intent intent = new Intent();               intent.setAction(""com.hly.view.fling"");                intent.putExtra(""key""""name"");                startActivity(intent); 

鴻蒙:

A.在config.json文件ability 中添加以下信息

  1. "skills"":[ 
  2.      { 
  3.         ""actions"":[ 
  4.             ""ability.intent.gotopage"" 
  5.             ] 
  6.     } 

B.在MainAbility的onStart函數(shù)中,增加頁面路由

  1. addActionRoute( ""ability.intent.gotopage"", BSlice.class.getName()); 

C.跳轉(zhuǎn)

  1. Intent intent = new Intent(); 
  2.             intent.setAction(""ability.intent.gotopage""); 
  3.             startAbility(intent); 

3.頁面碎片

安卓:

  1. Fragment 

鴻蒙:

 

  1. Fraction 

A:Ability繼承FractionAbility

B:獲取Fraction調(diào)度器

  1. getFractionManager().startFractionScheduler() 

C:構(gòu)造Fraction

D:調(diào)用調(diào)度器管理Fraction

  1. FractionScheduler.add() 
  2. FractionScheduler.remove() 
  3. FractionScheduler.replace() 

備注:

參考demo

https://www.jianshu.com/p/58558dc6673a"

4.從xml文件創(chuàng)建一個(gè)組件實(shí)例

安卓:

  1. LayoutInflater.from(mContext).inflate(R.layout.banner_viewpager_layout, null); 

鴻蒙:

  1. LayoutScatter.getInstance(getContext()).parse(ResourceTable.Layout_ability_main, nullfalse); 

5.組件自定義繪制

安卓:

  1. ImageView.setImageDrawable(Drawable drawable); 

并重寫Drawable 的draw函數(shù)

鴻蒙:

  1. Component.addDrawTask(Component.DrawTask task); 

并實(shí)現(xiàn)Component.DrawTask接口的onDraw函數(shù)

6.自定義組件的自定義屬性(在xml中使用)

安卓:

需要3步

A.在 values/attrs.xml,在其中編寫 styleable 和 item 等標(biāo)簽元素。

B.在layout.xml中,增加

  1. xmln:app= ""http://schemas.android.com/apk/res/-auto"" 

C.在自定義組件的構(gòu)造函數(shù)中,調(diào)用array.getInteger(R.styleable.***, 100);獲取屬性

鴻蒙:

只需2步

A. 在組件定義的layout.xml中增加 xmlns:app=""http://schemas.huawei.com/apk/res/ohos""

然后就可以使用app:***(***為任意字符串)來增加自定義屬性了,為了區(qū)分建議加上組件名前綴。

B. 在自定義組件的帶AttrSet參數(shù)的構(gòu)造函數(shù)中,使用下面代碼獲取屬性。attrSet.getAttr(""***"").get().getStringValue();

7.觸摸事件

安卓:

  1. android.view.MotionEvent 

鴻蒙:

  1. ohos.multimodalinput.event.TouchEvent 

8.事件處理

安卓:

  1. android.os.Handler 

鴻蒙:

  1. ohos.eventhandler.EventHandler 

9.控件觸摸事件回調(diào)

安卓:

  1. android.view.View.OnTouchListener 

 鴻蒙:

  1. ohos.agp.components.Component. 
  2. TouchEventListener 

10.輪播圖繼承的父類

安卓:

  1. extends ViewPager 

鴻蒙:

  1. extends PageSlider 

11.實(shí)現(xiàn)監(jiān)聽輪播圖組件事件

安卓:

  1. implements PageSlider.PageChangedListener 

鴻蒙:

  1. Implements OnPageChangedListener 

12.touch事件監(jiān)聽

安卓:

  1. 直接重寫onTouchEvent 

鴻蒙:

  1. 繼承 Component.TouchEventListener然后在構(gòu)造方法中設(shè)置監(jiān)聽 setTouchEventListener(this::onTouchEvent);實(shí)現(xiàn)onTouchEvent 

13.獲取點(diǎn)擊事件的坐標(biāo)點(diǎn)

安卓:

  1. event.getX(), event.getY() 

鴻蒙:

  1. MmiPoint point = touchEvent.getPointerPosition(touchEvent.getIndex()); 

14.調(diào)節(jié)滾輪中內(nèi)容間距

安卓:

  1. setLineSpacingMultiplier(float f) 

鴻蒙:

  1. setSelectedNormalTextMarginRatio(float f) 

15.滾輪定位

安卓:

  1. setPosition 

鴻蒙:

  1. setValue 

16.Layout布局改變監(jiān)聽

安卓:

  1. View.OnLayoutChangeListener 

鴻蒙:

  1. Component.LayoutRefreshedListener 

17.組件容器

安卓:

  1. ViewGroup 

鴻蒙:

  1. ComponentContainer 

18.添加組件

安卓:

  1. addView() 

鴻蒙:

  1. addComponent() 

19.動(dòng)態(tài)列表的適配器

安卓:

  1. extends RecyclerView.Adapter<> 

鴻蒙:

  1. extends RecycleItemProvider 

20.動(dòng)態(tài)列表

安卓:

  1. RecyclerView 

鴻蒙:

  1. ListContainer 

21.文本域動(dòng)態(tài)監(jiān)聽

安卓:

  1. TextWatcher 

鴻蒙:

  1. Component.ComponentStateChangedListener 

22.組件繪制自定義布局

安卓:

  1. 重寫onLayout(boolean changed, int leftint topint rightint bottom) 

鴻蒙:

  1. 重寫Component.LayoutRefreshedListener的onRefreshed方法 

23.List組件

安卓:

  1. ListView 

鴻蒙:

  1. ListContainer 

24.設(shè)置背景顏色

安卓:

  1. setBackgroundColor(maskColor); 

 鴻蒙:

  1. // 創(chuàng)建背景元素 
  2. ShapeElement shapeElement = new ShapeElement(); 
  3. // 設(shè)置顏色 
  4. shapeElement.setRgbColor(new RgbColor(255, 0, 0)); 
  5. view.setBackground(shapeElement); 

25.可以在控件上、下、左、右設(shè)置圖標(biāo),大小按比例自適應(yīng)

安卓:

  1. setCompoundDrawablesWithIntrinsicBounds 

鴻蒙:

  1. setAroundElements 

26.RadioButton組件在xml中如何設(shè)置checked屬性

安卓:

在xml中可以設(shè)置

鴻蒙:

  1. radioButton = findComponentById(); 
  2. radioButton.setChecked(true); 

備注:

sdk2.0后 xml中沒有了checked屬性,如果使用,可以在java代碼中實(shí)現(xiàn)"

27.文本域動(dòng)態(tài)監(jiān)聽

安卓:

  1. TextWatcher 

鴻蒙:

  1. Component.ComponentStateChangedListener 

28.顏色類

安卓:

  1. java.awt.Color 

鴻蒙:

  1. ohos.agb.colors.rgbcolor 

29.為ckeckbox或者Switch按鈕設(shè)置資源圖片

安卓:

鴻蒙:

  1. VectorElement vectorElement = new VectorElement(this, ResourceTable.Graphic_candy); 
  2. setBackground(vectorElement) 

30.子組件將拖拽事件傳遞給父組件

安卓:

鴻蒙:

注冊(cè)setDraggedListener偵聽,實(shí)現(xiàn)onDragPreAccept方法,再方法內(nèi)根據(jù)拖拽方向判斷是否需要父組件處理,如果需要?jiǎng)t返回false,否則返回true

※資源管理

1.管理資源

安卓:

  1. AssertManager 

鴻蒙:

  1. ResourceManager 

2.獲取應(yīng)用的資源文件rawFile,并返回InputStream

安卓:

  1. getResources() 
  2.  
  3. AssetManager類 

 鴻蒙:

  1. ResourceManager resourceManager = getContext().getResourceManager(); 
  2.         RawFileEntry rawFileEntry = resourceManager.getRawFileEntry(jsonFile); 
  3.         Resource resource = null
  4.         try { 
  5.             resource = rawFileEntry.openRawFile(); 
  6.         } catch (IOException e) { 
  7.             e.printStackTrace(); 
  8.         } 

備注:

  1. Resource是InputStream的子類,可以直接作為InputStream使用。" 

3.獲取文件路徑

安卓:

  1. Environment.getExternalStorageDirectory().getAbsolutePath() 

鴻蒙:

  1. 獲取文檔(DIRECTORY_DOCUMENTS)、下載(DIRECTORY_DOWNLOADS)、視頻(DIRECTORY_MOVIES)、音樂(DIRECTORY_MUSIC)、圖片(DIRECTORY_PICTURES) 
  2.  
  3. GetExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath() 

 ※消息&多線程

1.事件循環(huán)器

安卓:

  1. android.os.Looper 

鴻蒙:

  1. EventRunner.create(true

備注:

有參數(shù)且為true,表示隊(duì)列被托管,參數(shù)為false,或無參表示不被托管,需要eventRunner.run()調(diào)用

2.消息

安卓:

  1. android.os.Message 

鴻蒙:

  1. InnerEvent 

3.休眠

安卓:

  1. android.os.SystemClock.sleep() 

 鴻蒙:

  1. ohos.miscservices.timeutility.time
  2. Time.sleep(int millesend) 

4.事件通知延遲消息

安卓:

  1. Handler.postDelayed(MESSAGE_LOGIN, 5000); 

鴻蒙:

  1. Handler.postTask(task, 5000); 

5.Intent傳遞參數(shù)

安卓:

  1. Intent.putExtra or add Bundle 

鴻蒙:

  1. Intent.setParam 

6.消息發(fā)送

安卓:

  1. Handler handler = new Handler,通過handlerMsg發(fā)消息 

 鴻蒙:

  1. InnerEvent event1 = InnerEvent.get(eventId1, param, object); 
  2.         myHandler.sendEvent(event1, 0, Priority.IMMEDIATE); 

7.更新UI

安卓:

  1. class MyHandle extends Handler{ 
  2.        @Override 
  3.        public void handleMessage(Message msg) { 
  4.            super.handleMessage(msg); 
  5.            switch (msg.what) { 
  6.                case 1: 
  7.                    //更新UI的操作 
  8.                    break; 
  9.                default
  10.                    Break; 
  11.            } 
  12.        } 
  13.    } 

鴻蒙:

  1. abilitySlice.getUITaskDispatcher().asyncDispatch(() -> { 
  2.     //更新UI的操作 
  3. }); 

※圖片處理

1.位圖資源

安卓:

  1. Bitmap 

鴻蒙:

  1. PixelMap 

2.圖像縮放,拉伸到視圖邊界

安卓:

  1. ImageView.ScaleType 
  2. image.setScaleType(ScaleType.FXY); 

鴻蒙:

  1. Image.ScaleMode 
  2. image.setScaleMode(Image.ScaleMode.STRETCH); 

3.List組件&內(nèi)容適配器

安卓:

  1. ListView 
  2. extends BaeAdapter 
  3. ViewPage.setAdapter(BaeAdapter); 

鴻蒙:

  1. ListContainer 
  2. extends PageSlider 
  3. PageSlider.setProvider(PageSlider); 

4.圖片顯示組件

安卓:

  1. androidx.appcompat.widget.AppCompatImageView 
  2. Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),drawableId); 
  3. Image.setImageBitmap(bitmap); 

鴻蒙:

  1. ohos.agp.components.Image 

 根據(jù)實(shí)際情況可傳遞其他參數(shù)

  1. ImageSource imageSource = ImageSource.create(file, new ImageSource.SourceOptions()); 
  2. pixelMap = imageSource.createPixelmap(new ImageSource.DecodingOptions()); 
  3. image.setPixelMap(pixelMap); 

5.圖片填充整個(gè)控件

安卓:

  1. image.setScaleType(ScaleType.FXY); 

鴻蒙:

  1. image.setScaleMode(Image.ScaleMode.STRETCH); 

6.通過資源id獲取位圖

安卓:

  1. getBitmapFromDrawable 

 鴻蒙:

  1. /** 
  2.     * 通過資源ID獲取位圖對(duì)象 
  3.     **/ 
  4.    private PixelMap getPixelMap(int resId) { 
  5.        InputStream drawableInputStream = null
  6.        try { 
  7.            drawableInputStream = getResourceManager().getResource(resId); 
  8.            ImageSource.SourceOptions sourceOptions = new ImageSource.SourceOptions(); 
  9.            sourceOptions.formatHint = ""image/png""
  10.            ImageSource imageSource = ImageSource.create(drawableInputStream, null); 
  11.            ImageSource.DecodingOptions decodingOptions = new ImageSource.DecodingOptions(); 
  12.            decodingOptions.desiredSize = new Size(0, 0); 
  13.            decodingOptions.desiredRegion = new Rect(0, 0, 0, 0); 
  14.            decodingOptions.desiredPixelFormat = PixelFormat.ARGB_8888; 
  15.            PixelMap pixelMap = imageSource.createPixelmap(decodingOptions); 
  16.            return pixelMap; 
  17.        } catch (Exception e) { 
  18.            e.printStackTrace(); 
  19.        } finally { 
  20.            try { 
  21.                if (drawableInputStream != null) { 
  22.                    drawableInputStream.close(); 
  23.                } 
  24.            } catch (Exception e) { 
  25.                e.printStackTrace(); 
  26.            } 
  27.        } 
  28.        return null
  29.    } 

7.獲取Gif圖片幀

安卓:

需要自定frame類,通過decoder獲取

鴻蒙:

  1. ImageSource.createPixelmap(int index, ImageSource.DecodingOptions opts) 

8.BMP位圖裁剪

安卓:

  1. Bitmap.createBitmap(Bitmap source, int x, int y, int width, int height) 

鴻蒙:

  1. PixelMap.create​(PixelMap source, Rect srcRegion, PixelMap.InitializationOptions opts) 

※視頻播放

在視頻播放窗口上層增加控件

安卓:

鴻蒙:

A.pinToTop設(shè)置false,保證其他控件與surfaceProvider在同一layout下,并且不能設(shè)置背景

B.增加以下代碼設(shè)置頂部窗口透明

  1. WindowManager.getInstance().getTopWindow().get().setTransparent(true); 

※數(shù)據(jù)庫

數(shù)據(jù)庫獲取索引

安卓:

  1. android.database.Cursor
  2. cursor.getString()/cursor.getColumnIndex() 

鴻蒙:

  1. ohos.data.resultset 

※數(shù)據(jù)結(jié)構(gòu)

1.應(yīng)用程序數(shù)據(jù)共享

安卓:

  1. context.getContentResolver(); 
  2. resolver.getType(uri) 

鴻蒙:

  1. ohos.aafwk.ability.DataAbilityHelper 

2.JSON解析

安卓:

  1. import org.json.JSONArray; 
  2. import org.json.JSONException; 
  3. import org.json.JSONObject; 
  4. import org.json.JSONTokener; 

鴻蒙:

  1. Gson,fastJson 

3.對(duì)象序列化

安卓:

  1. android.os.Parcel; 
  2. parcel.readParcelable();parcel.writeParcelable() 

鴻蒙:

  1. ohos.utils.parcel 

4.浮點(diǎn)數(shù)矩形,獲取中心點(diǎn)

安卓:

  1. RectF.centerX() 

鴻蒙:

  1. RectFloat.getCenter().getPointX() 

5.數(shù)據(jù)結(jié)構(gòu)類

安卓:

  1. LongSparseArray 
  2. SparseArrayCompat 

鴻蒙:

使用HashMap

備注:

內(nèi)存使用和查找性能會(huì)有影響。"

6.浮點(diǎn)數(shù)矩形

安卓:

  1. RectF 

鴻蒙:

  1. RectFloat 

7.浮點(diǎn)坐標(biāo)

安卓:

  1. PointF 

鴻蒙:

  1. 可使用Point 

※對(duì)話框

1.對(duì)話框銷毀

安卓:

  1. mDialog.dismiss() 

鴻蒙:

  1. mDialog.destroy(); 

2.對(duì)話框中加載布局

安卓:

  1. mDialog.setContentView(ViewGroup dialogView) 

鴻蒙:

  1. setContentCustomComponent(Componnet comp) 

3.點(diǎn)擊對(duì)話框外部關(guān)閉對(duì)話框

安卓:

  1. mDialog.setCancelable(mPickerOptions.cancelable) 

 鴻蒙:

  1. mDialog.setDialogListener(new BaseDialog.DialogListener() { 
  2.                @Override 
  3.                public boolean isTouchOutside() { 
  4.                    mDialog.destroy();                dialogView.getComponentParent().removeComponent(dialogView); 
  5.                    return true
  6.                } 
  7.            }); 

備注:

鴻蒙對(duì)話框銷毀之后需移除對(duì)話框中加載的布局,否則再次加載會(huì)報(bào)錯(cuò)"

※動(dòng)畫

1.旋轉(zhuǎn)動(dòng)畫

安卓:

  1. android.view.animation.RotateAnimation 

鴻蒙:

  1. ohos.agp.animation.AnimatorProperty 

2.值動(dòng)畫及相關(guān)回調(diào)

安卓:

  1. android.animation.ValueAnimator 
  2. ValueAnimator.AnimatorUpdateListener 
  3. Animator.AnimatorListener 
  4. Animator.AnimatorPauseListener 

鴻蒙:

  1. ohos.agp.animation.AnimatorValue 
  2. AnimatorValue.ValueUpdateListener 
  3. Animator.StateChangedListener 
  4. Animator.LoopedListener 

備注:

啟動(dòng)動(dòng)畫時(shí),AnimatorValue必須作為類的成員變量,而不能時(shí)函數(shù)局部變量,否則動(dòng)畫不會(huì)啟動(dòng)"

3.線性插值器

安卓:

  1. LinearInterpolator 

鴻蒙:

自己寫一個(gè)

  1. public interface Interpolator { 
  2.     float getInterpolation(float input); 
  3. public class LinearInterpolator implements Interpolator { 
  4.     public LinearInterpolator() { 
  5.     } 
  6.     public LinearInterpolator(Context context, AttrSet attrs) { 
  7.     } 
  8.     public float getInterpolation(float input) { 
  9.         return input; 
  10.     } 

4.設(shè)置動(dòng)畫循環(huán)次數(shù)

安卓:

  1. animation.setRepeatCount(Animation.INFINITE) 

鴻蒙:

  1. animator.setLoopedCount(Animator.INFINITE) 

※存儲(chǔ)

獲取存儲(chǔ)根路徑

安卓:

  1. Environment.getExternalStorageDirectory().getAbsolutePath(); 

鴻蒙:

  1. System.getProperty("user.dir"

※Canvas繪圖

1.繪制圓弧

安卓:

  1. Android canvas.drawArc() 

鴻蒙:

  1. ohos.agp.render; class Arc 

2.繪制圓形的兩種方式

安卓:

  1. canvas.drawCircle(float x, float y, float radius, Paint paint) 

鴻蒙:

  1. A.canvas.drawPixelMapHolderRoundRectShape(PixelMapHolder holder, RectFloat rectSrc, RectFloat rectDst, float radiusX, float radiusY) 
  2.  
  3. B.canvas.drawCircle(float x, float y, float radius, Paint paint) 

 3.繪制文本的方法

安卓:

  1. drawText (String text, float x, float y, Paint paint) 

鴻蒙:

  1. drawText(Paint paint, String text, float x, float y) 

4.獲取text 的寬度

安卓:

  1. text.getWidth(); 

 鴻蒙:

  1. Paint paint = new Paint(); 
  2. paint.setTextSize(text.getTextSize()); 
  3. float childWidth = paint.measureText(text.getText()); 

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

想了解更多內(nèi)容,請(qǐng)?jiān)L問:

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

https://harmonyos.51cto.com

 

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

2021-05-26 15:11:09

鴻蒙HarmonyOS應(yīng)用

2015-11-05 16:44:37

第三方登陸android源碼

2021-03-10 15:03:40

鴻蒙HarmonyOS應(yīng)用

2013-06-09 09:38:44

安卓第三方ROM谷歌Android

2017-09-26 11:29:29

安卓

2014-07-23 08:55:42

iOSFMDB

2019-07-30 11:35:54

AndroidRetrofit

2021-03-03 09:42:26

鴻蒙HarmonyOS圖片裁剪

2019-09-03 18:31:19

第三方支付電商支付行業(yè)

2009-12-31 14:38:34

Silverlight

2016-10-21 14:09:10

2017-12-11 15:53:56

2021-08-03 10:07:41

鴻蒙HarmonyOS應(yīng)用

2021-03-01 14:00:11

鴻蒙HarmonyOS應(yīng)用

2020-03-10 10:19:42

安卓威脅安全

2021-10-17 22:30:37

安卓系統(tǒng)蘋果

2022-01-14 09:57:14

鴻蒙HarmonyOS應(yīng)用

2021-03-24 09:30:49

鴻蒙HarmonyOS應(yīng)用

2021-03-12 16:35:33

鴻蒙HarmonyOS應(yīng)用

2021-08-26 16:07:46

鴻蒙HarmonyOS應(yīng)用
點(diǎn)贊
收藏

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