添加Layout页面
This commit is contained in:
@@ -73,20 +73,20 @@ export struct TitleBar {
|
||||
if (this.titleVisible == Visibility.Visible) {
|
||||
Text(this.title)
|
||||
.textAlign(this.titleTextAlign)
|
||||
.margin({
|
||||
left: this.leftMenuType != TitleBarMenuType.None ? this.barHeight : 0,
|
||||
right: this.leftMenuType != TitleBarMenuType.None ? this.barHeight : 0
|
||||
.backgroundColor(0xFFFFFF)
|
||||
.padding({
|
||||
left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding,
|
||||
right: this.rightMenuType != TitleBarMenuType.None ? 0 : this.menuPadding
|
||||
})
|
||||
.padding({left: this.leftMenuType != TitleBarMenuType.None ? 0 : this.menuPadding})
|
||||
.alignRules({
|
||||
top: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Top },
|
||||
left: {
|
||||
anchor: this.leftMenuType != TitleBarMenuType.None ? "left_menu" : ComponentConst.ContainerId,
|
||||
align: HorizontalAlign.Start
|
||||
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.End : HorizontalAlign.Start
|
||||
},
|
||||
right: {
|
||||
anchor: this.leftMenuType != TitleBarMenuType.None ? "right_menu" : ComponentConst.ContainerId,
|
||||
align: HorizontalAlign.End
|
||||
align: this.leftMenuType != TitleBarMenuType.None ? HorizontalAlign.Start : HorizontalAlign.End
|
||||
},
|
||||
bottom: { anchor: ComponentConst.ContainerId, align: VerticalAlign.Bottom }
|
||||
})
|
||||
|
16
common_ui/src/main/ets/pages/layout/LinearLayoutPage.ets
Normal file
16
common_ui/src/main/ets/pages/layout/LinearLayoutPage.ets
Normal file
@@ -0,0 +1,16 @@
|
||||
|
||||
@Entry
|
||||
@Component
|
||||
struct LinearLayoutPage {
|
||||
|
||||
@State space: number = 10;
|
||||
|
||||
build() {
|
||||
Column({ space: this.space }) {
|
||||
Text(`space:${this.space}`)
|
||||
Row().width('90%')
|
||||
Row().width('90%')
|
||||
Row().width('90%')
|
||||
}
|
||||
}
|
||||
}
|
101
common_ui/src/main/ets/utils/ScreenUtil.ets
Normal file
101
common_ui/src/main/ets/utils/ScreenUtil.ets
Normal file
@@ -0,0 +1,101 @@
|
||||
import window from '@ohos.window';
|
||||
|
||||
export class ScreenUtil {
|
||||
// TODO: 工具待抽离, key统一定义
|
||||
static readonly isPortraitKey: string = "xy_screen_is_portrait";
|
||||
private static instance: ScreenUtil;
|
||||
public width: number = 0
|
||||
public height: number = 0
|
||||
public statusBarHeight: number = 0
|
||||
public bottomSafeHeight: number = 0
|
||||
public contentHeight: number = 0;
|
||||
|
||||
public layoutWidth: number = 0
|
||||
public layoutHeight: number = 0
|
||||
|
||||
|
||||
public static getInstance(): ScreenUtil {
|
||||
if (!ScreenUtil.instance) {
|
||||
ScreenUtil.instance = new ScreenUtil();
|
||||
}
|
||||
return ScreenUtil.instance;
|
||||
}
|
||||
|
||||
initScreenSize(): void {
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
let type = window.AvoidAreaType.TYPE_NAVIGATION_INDICATOR; // 以导航条避让为例
|
||||
let avoidArea = windowClass.getWindowAvoidArea(type);
|
||||
this.bottomSafeHeight = px2vp(avoidArea.bottomRect.height); // 获取到导航条区域的高度
|
||||
type = window.AvoidAreaType.TYPE_SYSTEM;
|
||||
avoidArea = windowClass.getWindowAvoidArea(type);
|
||||
this.statusBarHeight = px2vp(avoidArea.topRect.height);
|
||||
this.width = px2vp(windowClass.getWindowProperties().windowRect.width);
|
||||
this.height = px2vp(windowClass.getWindowProperties().windowRect.height);
|
||||
this.layoutWidth = this.width;
|
||||
this.layoutHeight = this.height - this.statusBarHeight - this.bottomSafeHeight;
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
|
||||
setPreferredOrientation(orientation: window.Orientation): void {
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
windowClass.setPreferredOrientation(orientation);
|
||||
AppStorage.setOrCreate(ScreenUtil.isPortraitKey, orientation == window.Orientation.PORTRAIT || orientation == window.Orientation.PORTRAIT_INVERTED);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
|
||||
setPreferredOrientationCallBack(orientation: window.Orientation, callback: ()=>void): void{
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
windowClass.setPreferredOrientation(orientation,callback);
|
||||
AppStorage.setOrCreate(ScreenUtil.isPortraitKey, orientation == window.Orientation.PORTRAIT || orientation == window.Orientation.PORTRAIT_INVERTED);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
|
||||
setWindowLayoutFullScreen(isLayoutFullScreen: boolean): void {
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
windowClass.setWindowLayoutFullScreen(isLayoutFullScreen);
|
||||
windowClass.setSpecificSystemBarEnabled('status', !isLayoutFullScreen);
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
|
||||
setWindowSystemBarProperties(systemBarProperties: window.SystemBarProperties): void {
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
windowClass.setWindowSystemBarProperties(systemBarProperties, (err) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in setting the system bar properties.');
|
||||
});
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
|
||||
setWindowSystemBarEnable(names:Array<'status' | 'navigation'>){
|
||||
window.getLastWindow(getContext(this))
|
||||
.then((windowClass: window.Window) => {
|
||||
windowClass.setWindowSystemBarEnable(names, (err) => {
|
||||
if (err.code) {
|
||||
console.error('Failed to set the system bar properties. Cause: ' + JSON.stringify(err));
|
||||
return;
|
||||
}
|
||||
console.info('Succeeded in setting the system bar properties.');
|
||||
});
|
||||
})
|
||||
.catch((error: Error) => {
|
||||
})
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user