HarmonyOS swiper使用LazyForEach加载数据时,界面展示异常

进入swiper界面后,最先展示的一屏布局是对的,左右滑动展示的都是向顶部靠拢的,然后点击界面一个展开菜单的动画,布局又自动回归到正常。

HarmonyOS
2天前
浏览
收藏 0
回答 1
待解决
回答 1
按赞同
/
按时间
superinsect

可以通过setWindowLayoutFullScreen+margin的方式来实现:

//EntryAbility.ets
//替换掉此方法
onWindowStageCreate(windowStage: window.WindowStage): void {
  // Main window is created, set main page for this ability
  hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate');

  windowStage.loadContent('pages/Index', (err, data) => {
  if (err.code) {
  hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
  return;
}
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');

let windowClass = windowStage.getMainWindowSync()
AppStorage.setOrCreate('windowClass',windowClass)

let statusHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_SYSTEM).topRect.height;
let bottomHeight = windowClass.getWindowAvoidArea(window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR).bottomRect.height;
AppStorage.setOrCreate('bottomHeight',px2vp(bottomHeight));
AppStorage.setOrCreate('statusHeight',px2vp(statusHeight));
});
}
//SecondPage.ets
import { DataBean } from '../data/DataBean';
import { Data } from '../data/ResultForReaded';
import { WaterFlowDataSource } from '../data/WaterFlowDataSource';
import { AppRouter } from '../model/AppRouter';
import { CaseDialog } from '../model/CaseDialog';
import { window } from '@kit.ArkUI';

@Entry
@Component
struct SecondPage {
  @Provide('pageInfos') pageInfos: NavPathStack = new NavPathStack()

  onPageShow(): void {
    (AppStorage.get('windowClass') as window.Window).setWindowLayoutFullScreen(true)
  }

  onPageHide(): void {
    (AppStorage.get('windowClass') as window.Window).setWindowLayoutFullScreen(false)
  }

  aboutToAppear() {
    AppRouter.getInstance().register(this.pageInfos);

    let listData = new Array<DataBean>()
    for (let index = 0; index < 10; index++) {
      listData.push(new DataBean(index))
    }
    this.myData.setRefreshData(listData)
  }

  @Builder
  PageMap(name: string) {
    if (name === 'dialog') {
      CaseDialog()
    }
  }

  myData: WaterFlowDataSource = new WaterFlowDataSource()

  build() {
    Swiper() {
      LazyForEach(this.myData, (item: DataBean, index: number) => {
        Column() {
          GridRow({ columns: { sm: 8, md: 8, lg: 8 } }) {
            GridCol({ span: { sm: 4, md: 4, lg: 4 } }) {
              this.item1(item)
            }

            GridCol({ span: { sm: 4, md: 4, lg: 4 } }) {
              this.item2(item)
            }
          }
        }.width("100%").height("100%")
        .justifyContent(FlexAlign.Center)
      }, (item: DataBean) => item.index.toString())
    }
    .margin({ bottom: (AppStorage.get('bottomHeight') as number) })
    .indicator(false)
    .backgroundColor(Color.Red)
    .loop(false)
    .autoPlay(false)
    .width("100%")
    .index(2)
    .onChange(index => {
    })
  }

  @Builder
  item1(item: DataBean) {
    Stack() {
      Column() {
        Text("item:" + item.index)
          .backgroundColor(Color.Yellow)
          .width("100%").height("100%")
          .layoutWeight(1)
      }
    }.alignContent(Alignment.TopStart)
  }

  @Builder
  item2(item: DataBean) {
    Column() {
      Text("item2:" + item.index)
        .backgroundColor(Color.Blue)
        .width("100%").height("100%")
        .layoutWeight(1)
    }
  }
}
分享
微博
QQ
微信
回复
2天前
相关问题
HarmonyOS swiper + LazyForEach使用问题
353浏览 • 1回复 待解决
HarmonyOS Text加载藏文,显示异常
76浏览 • 1回复 待解决
HarmonyOS 关于Swiper+LazyForEach方案咨询
33浏览 • 1回复 待解决
使用LazyForEach加载列表相关问题
887浏览 • 1回复 待解决
使用List lazyForeach,reuseId未生效
329浏览 • 1回复 待解决
HarmonyOS Imageknife 动图展示异常
367浏览 • 1回复 待解决
HarmonyOS 数据库的beginTrans使用异常
188浏览 • 1回复 待解决