北向应用:Car页面布局与跳转测试 原创
显示效果:
点击“点击了解更多”进入下一个页面
代码如下:
第一个页面的布局
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
<DirectionalLayout
ohos:width="match_parent"
ohos:weight="1">
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:text="蛟龙腾飞"
ohos:text_size="20fp"
ohos:top_margin="40px"
ohos:left_margin="80px"/>
</DirectionalLayout>
<DirectionalLayout
ohos:width="match_parent"
ohos:weight="4"
ohos:orientation="horizontal">
<DirectionalLayout
ohos:height="match_parent"
ohos:weight="1">
<Image
ohos:width="526px"
ohos:height="504px"
ohos:top_margin="-50px"
ohos:left_margin="20px"
ohos:image_src="$media:index20"/>
</DirectionalLayout>
<DirectionalLayout
ohos:height="match_parent"
ohos:weight="2">
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:multiple_lines="true"
ohos:text="带你从传统的互联网、移动互联网时代
跳转到万物互联的智能世界!
ohos:text_size="20fp"
ohos:top_margin="20px"
ohos:left_margin="60px"/>
<Button
ohos:id="$+id:jltfbutton"
ohos:width="match_content"
ohos:height="match_content"
ohos:text="点击了解更多"
ohos:text_size="25fp"
ohos:top_margin="60px"
ohos:left_margin="650px"
ohos:text_color="red"/>
</DirectionalLayout>
</DirectionalLayout>
</DirectionalLayout>
第二个页面的布局
<?xml version="1.0" encoding="utf-8"?>
<DirectionalLayout
xmlns:ohos="http://schemas.huawei.com/res/ohos"
ohos:height="match_parent"
ohos:width="match_parent"
ohos:orientation="vertical">
<DirectionalLayout
ohos:width="match_parent"
ohos:weight="1"
>
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:text="蛟龙腾飞"
ohos:text_size="20fp"
ohos:top_margin="40px"
ohos:left_margin="80px"/>
</DirectionalLayout>
<DirectionalLayout
ohos:width="match_parent"
ohos:weight="4"
ohos:orientation="horizontal">
<DirectionalLayout
ohos:height="match_parent"
ohos:weight="1">
<Image
ohos:width="357px"
ohos:height="360px"
ohos:top_margin="60px"
ohos:left_margin="100px"
ohos:image_src="$media:index4"/>
</DirectionalLayout>
<DirectionalLayout
ohos:height="match_parent"
ohos:weight="2">
<Text
ohos:width="match_content"
ohos:height="match_content"
ohos:multiple_lines="true"
ohos:text="你好,欢迎来到鸿蒙时代!
ohos:text_size="20fp"
ohos:top_margin="60px"
ohos:left_margin="10px"/>
</DirectionalLayout>
</DirectionalLayout>
</DirectionalLayout>
然后绑定布局进行跳转
Button button = (Button) findComponentById(ResourceTable.Id_jltfbutton);
button.setClickedListener(new Component.ClickedListener() {
@Override
public void onClick(Component component) {
present(new jltftabletSlice(),new Intent());
}
});