From 6eb7ccec332c5b938403d465934425741485c09c Mon Sep 17 00:00:00 2001 From: rex <1491721419@qq.com> Date: Mon, 13 Oct 2025 11:45:16 +0800 Subject: [PATCH] =?UTF-8?q?Proper=5FUse=5FLayout=E5=B7=A5=E7=A8=8B?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../entry/src/main/ets/pages/Index.ets | 43 ++++++++++++++----- .../resources/base/profile/main_pages.json | 4 +- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ArkUI/Proper_Use_Layout/entry/src/main/ets/pages/Index.ets b/ArkUI/Proper_Use_Layout/entry/src/main/ets/pages/Index.ets index 6db84a6a..c149968e 100644 --- a/ArkUI/Proper_Use_Layout/entry/src/main/ets/pages/Index.ets +++ b/ArkUI/Proper_Use_Layout/entry/src/main/ets/pages/Index.ets @@ -12,27 +12,48 @@ * See the License for the specific language governing permissions and * limitations under the License. */ +import { BusinessError } from '@kit.BasicServicesKit'; +import { hilog } from '@kit.PerformanceAnalysisKit'; @Entry @Component struct Index { - @State message: string = 'Hello World'; - build() { - RelativeContainer() { - Text(this.message) - .id('HelloWorld') - .fontSize($r('app.float.page_text_font_size')) - .fontWeight(FontWeight.Bold) - .alignRules({ - center: { anchor: '__container__', align: VerticalAlign.Center }, - middle: { anchor: '__container__', align: HorizontalAlign.Center } + Column({ space: 15 }) { + Button('to segment2') + .width('100%') + .onClick(() => { + this.getUIContext() + .getRouter() + .pushUrl({ + url: 'segment/segment2' + }) + .then(() => { + hilog.info(0x000, 'testTag', `pushUrl succeed.`); + }) + .catch((err: BusinessError) => { + hilog.warn(0x000, 'testTag', `pushUrl failed. code=${err.code}, message=${err.message}`); + }) }) + Button('to segment3') + .width('100%') .onClick(() => { - this.message = 'Welcome'; + this.getUIContext() + .getRouter() + .pushUrl({ + url: 'segment/segment3' + }) + .then(() => { + hilog.info(0x000, 'testTag', `pushUrl succeed.`); + }) + .catch((err: BusinessError) => { + hilog.warn(0x000, 'testTag', `pushUrl failed. code=${err.code}, message=${err.message}`); + }) }) } .height('100%') .width('100%') + .justifyContent(FlexAlign.End) + .padding({ left: 12, right: 12, bottom: 15 }) } } \ No newline at end of file diff --git a/ArkUI/Proper_Use_Layout/entry/src/main/resources/base/profile/main_pages.json b/ArkUI/Proper_Use_Layout/entry/src/main/resources/base/profile/main_pages.json index 1898d94f..7230a3f2 100644 --- a/ArkUI/Proper_Use_Layout/entry/src/main/resources/base/profile/main_pages.json +++ b/ArkUI/Proper_Use_Layout/entry/src/main/resources/base/profile/main_pages.json @@ -1,5 +1,7 @@ { "src": [ - "pages/Index" + "pages/Index", + "segment/segment2", + "segment/segment3" ] } -- Gitee