點擊藍字 ╳ 關注我們
周黎生
OpenHarmony知識體系工作組
背景說明
組件選型,能力對比
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKGAHfl5AAEnJOoAXcM266.png)
重構前后能力對比
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKGAGrD5AADmFBtkAOY422.png)
重構完成的內容
重構中比較重要的點
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKGALneEAACp5bj46RE951.png)
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKGAXLMnAABrwYhmgxs396.jpg)
import {ImageKnifeComponent} from '@ohos/imageknife'
import {ImageKnifeOption} from '@ohos/imageknife'
import {ImageKnifeDrawFactory} from '@ohos/imageknife'
@Entry
@Component
struct Index {
@State imageKnifeOption1: ImageKnifeOption =
{ // 加載一張本地的png資源(必選)
loadSrc: $r('app.media.pngSample'),
// 主圖的展示模式是 縮放至適合組件大小,并且在組件底部繪制
mainScaleType: ScaleType.FIT_END,
// 占位圖使用本地資源icon_loading(可選)
placeholderSrc: $r('app.media.icon_loading'),
// 失敗占位圖使用本地資源icon_failed(可選)
errorholderSrc: $r('app.media.icon_failed'),
// 繪制圓角30,邊框5,邊框"#ff00ff".用戶自定義繪制(可選)
drawLifeCycle:ImageKnifeDrawFactory.createRoundLifeCycle(5,"#ff00ff",30)
};
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 })
.width(300) // 自定義組件已支持設置通用屬性和事件,這里寬高設置放在鏈式調用中完成
.height(300)
}
}
.width('100%')
.height('100%')
}
}
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKKAI9W4ADL8xKM_23Y599.gif)
import AbilityStage from '@ohos.application.Ability'
import { ImageKnife,ImageKnifeDrawFactory} from '@ohos/imageknife'
export default class EntryAbility extends Ability {
onCreate(want,launchParam) {
globalThis.ImageKnife = ImageKnife.with(this.context);
// 全局配置網絡加載進度條
globalThis.ImageKnife.setDefaultLifeCycle(ImageKnifeDrawFactory.createProgressLifeCycle("#10a5ff", 0.5))
}
}
![](https://file1.elecfans.com//web2/M00/99/8F/wKgZomTnhKKAWU6sABGNlYuz97E441.gif)
import {ImageKnifeComponent,ImageKnifeOption,ImageKnifeDrawFactory} from '@ohos/imageknife'
@Entry
@Component
struct Index {
@State imageKnifeOption1: ImageKnifeOption =
{ // 加載一張本地的png資源(必選)
loadSrc: $r('app.media.pngSample'),
};
build() {
Scroll() {
Flex({ direction: FlexDirection.Column, alignItems: ItemAlign.Center, justifyContent: FlexAlign.Center }) {
ImageKnifeComponent({ imageKnifeOption: this.imageKnifeOption1 })
.width(300) // 自定義組件已支持設置通用屬性和事件,這里寬高設置放在鏈式調用中完成
.height(300)
}
}
.width('100%')
.height('100%')
}
}
import {ImageKnifeOption,ImageKnifeComponent} from '@ohos/imageknife'
@Entry
@Component
struct BasicTestFeatureAbilityPage {
urls=[
"http://e.hiphotos.baidu.com/image/pic/item/a1ec08fa513d2697e542494057fbb2fb4316d81e.jpg",
"http://c.hiphotos.baidu.com/image/pic/item/30adcbef76094b36de8a2fe5a1cc7cd98d109d99.jpg",
"http://h.hiphotos.baidu.com/image/pic/item/7c1ed21b0ef41bd5f2c2a9e953da81cb39db3d1d.jpg",
"http://g.hiphotos.baidu.com/image/pic/item/55e736d12f2eb938d5277fd5d0628535e5dd6f4a.jpg",
"http://e.hiphotos.baidu.com/image/pic/item/4e4a20a4462309f7e41f5cfe760e0cf3d6cad6ee.jpg",
]
@State options:Array = []
aboutToAppear(){
this.options = this.urls.map((url)=>{
return {
loadSrc:url
}
})
console.log('this.options length ='+this.options.length)
}
build() {
Stack({ alignContent: Alignment.TopStart }) {
Column() {
List({ space: 20, initialIndex: 0 }) {
ForEach(this.options, (item) => {
ListItem() {
ImageKnifeComponent({imageKnifeOption:item}).width(300).height(300)
}
}, item => item.loadSrc)
}
.listDirection(Axis.Vertical) // 排列方向
.divider({ strokeWidth: 2, color: 0xFFFFFF, startMargin: 20, endMargin: 20 }) // 每行之間的分界線
.edgeEffect(EdgeEffect.None) // 滑動到邊緣無效果
.chainAnimation(false) // 聯動特效關閉
}.width('100%')
}.width('100%').height('100%').backgroundColor(0xDCDCDC).padding({ top: 5 })
}
}
渲染層重構的總結
原文標題:基于ArkUI框架開發-ImageKnife渲染層重構
文章出處:【微信公眾號:OpenAtom OpenHarmony】歡迎添加關注!文章轉載請注明出處。
聲明:本文內容及配圖由入駐作者撰寫或者入駐合作網站授權轉載。文章觀點僅代表作者本人,不代表電子發燒友網立場。文章及其配圖僅供工程師學習之用,如有內容侵權或者其他違規問題,請聯系本站處理。
舉報投訴
-
鴻蒙
+關注
關注
57文章
2393瀏覽量
43068 -
OpenHarmony
+關注
關注
25文章
3749瀏覽量
16597
原文標題:基于ArkUI框架開發-ImageKnife渲染層重構
文章出處:【微信號:gh_e4f28cfa3159,微信公眾號:OpenAtom OpenHarmony】歡迎添加關注!文章轉載請注明出處。
發布評論請先 登錄
相關推薦
華為推出RN/H5多設備自適應組件庫
存在大量用跨平臺框架開發的應用,部分頁面采用React Native(RN)和H5等框架開發,這些框架在系統級的多設備適配能力上相對有限,導致在折疊機、平板等設備上的適配效率不如ArkUI
ArkUI-X開發指南:【SDK配置和構建說明】
ArkUI-X SDK是ArkUI-X開源項目的編譯產物,可將ArkUI-X SDK集成到現有Android和iOS應用工程中,使開發者基于一套ArkTS主代碼,就可以構建支持多平臺的
![<b class='flag-5'>ArkUI</b>-X<b class='flag-5'>開發</b>指南:【SDK配置和構建說明】](https://file1.elecfans.com/web2/M00/C5/D1/wKgZomYChGOAUaiiAADe1d8SeRY102.jpg)
鴻蒙開發ArkUI-X基礎知識:【ArkUI代碼工程及構建介紹】
ArkUI作為OpenHarmony的默認開發框架,在本項目(ArkUI-X)中需要做到一套代碼同時支持多平臺構建,所以會采取共倉開發的方式
![鴻蒙<b class='flag-5'>開發</b><b class='flag-5'>ArkUI</b>-X基礎知識:【<b class='flag-5'>ArkUI</b>代碼工程及構建介紹】](https://file1.elecfans.com/web2/M00/C5/CD/wKgZomYCdwyAIFf5AAB_7E1pFms943.jpg)
鴻蒙ArkUI-X跨平臺開發:【bility開發說明(Android平臺)】
本文介紹將ArkUI框架擴展到Android平臺所需要的必要的類及其使用說明,開發者基于OpenHarmony,可復用大部分的應用代碼(生命周期等)并可以部署到Android平臺,降低跨平臺應用
![鴻蒙<b class='flag-5'>ArkUI</b>-X跨平臺<b class='flag-5'>開發</b>:【bility<b class='flag-5'>開發</b>說明(Android平臺)】](https://file1.elecfans.com/web2/M00/E7/51/wKgZomZLTACALdbCAAF8cNlebLs566.jpg)
評論