页面嵌套怎么做呢,想做个底部可切换tab的demo,

类似android的activity + viewpager + 多个fragment应该怎么搞啊?求大佬解惑。

页面嵌套
2021-01-18 17:19:06
浏览
收藏 0
回答 3
待解决
回答 3
按赞同
/
按时间
破茧_追梦
2

<?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:id="$+id:dl_frame"
        ohos:height="match_parent"
        ohos:width="match_parent"
        ohos:weight="1"/>

    <DirectionalLayout
        ohos:background_element="transparent"
        ohos:height="match_content"
        ohos:width="match_parent"
        ohos:orientation="horizontal">

        <DirectionalLayout
            ohos:id="$+id:listtenDL"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:top_margin="20vp"
            ohos:background_element="#ffffff"
            ohos:weight="1">
            <Text
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:id="$+id:home"
                ohos:bottom_margin="5vp"
                ohos:text_color="$color:color_f3"
                ohos:element_top="$media:shouye"
                ohos:text_alignment="center"
                ohos:layout_alignment="center"
                ohos:text_size="15fp"
                ohos:text="首页"/>
        </DirectionalLayout>
        <DirectionalLayout
            ohos:id="$+id:classlyDL"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:top_margin="20vp"
            ohos:background_element="#fff"
            ohos:weight="1">
            <Text
                ohos:id="$+id:classly"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:bottom_margin="5vp"
                ohos:text_color="$color:color_d0"
                ohos:element_top="$media:fenlei"
                ohos:text_alignment="center"
                ohos:layout_alignment="center"
                ohos:text_size="15fp"
                ohos:text="分类"/>
        </DirectionalLayout>
        <DirectionalLayout
            ohos:id="$+id:communityDL"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:top_margin="20vp"
            ohos:background_element="#fff"
            ohos:weight="1">
            <Text
                ohos:id="$+id:community"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:bottom_margin="5vp"
                ohos:text_color="$color:color_d0"
                ohos:element_top="$media:sq"
                ohos:text_alignment="center"
                ohos:text_size="15fp"
                ohos:layout_alignment="center"
                ohos:text="社区"/>
        </DirectionalLayout>
        <DirectionalLayout
            ohos:id="$+id:shopingDL"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:top_margin="20vp"
            ohos:background_element="#fff"
            ohos:weight="1">
            <Text
                ohos:id="$+id:shoping"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:bottom_margin="5vp"
                ohos:text_color="$color:color_d0"
                ohos:element_top="$media:gwc"
                ohos:text_alignment="center"
                ohos:layout_alignment="center"
                ohos:text_size="15fp"
                ohos:text="购物车"/>
        </DirectionalLayout>
        <DirectionalLayout
            ohos:id="$+id:myDL"
            ohos:height="match_content"
            ohos:width="match_content"
            ohos:top_margin="20vp"
            ohos:background_element="#fff"
            ohos:weight="1">
            <Text
                ohos:id="$+id:my"
                ohos:height="match_content"
                ohos:width="match_parent"
                ohos:bottom_margin="5vp"
                ohos:text_color="$color:color_d0"
                ohos:element_top="$media:my"
                ohos:text_alignment="center"
                ohos:layout_alignment="center"
                ohos:text_size="15fp"
                ohos:text="个人"/>
        </DirectionalLayout>

 

    </DirectionalLayout>


   

</DirectionalLayout>

分享
微博
QQ
微信
回复1
2021-01-18 17:37:15
破茧_追梦


public class MainAbilitySlice extends AbilitySlice {

    @BindView(value = ResourceTable.Id_dl_frame)
    DirectionalLayout dl_frame;
    @BindView(value = ResourceTable.Id_listtenDL)
    DirectionalLayout listtenDL;
    @BindView(value = ResourceTable.Id_classlyDL)
    DirectionalLayout classlyDL;
    @BindView(value = ResourceTable.Id_communityDL)
    DirectionalLayout communityDL;
    @BindView(value = ResourceTable.Id_shopingDL)
    DirectionalLayout shopingDL;
    @BindView(value = ResourceTable.Id_myDL)
    DirectionalLayout myDL;

    @BindView(value = ResourceTable.Id_home)
    Text home;
    @BindView(value = ResourceTable.Id_classly)
    Text classly;
    @BindView(value = ResourceTable.Id_community)
    Text community;
    @BindView(value = ResourceTable.Id_shoping)
    Text shoping;
    @BindView(value = ResourceTable.Id_my)
    Text my;


    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);
        ButterKnife.bind(this);
        //默认第一个
        setUI(new HomeSlice(), home);

    }

    @OnClick({ResourceTable.Id_home, ResourceTable.Id_classly, ResourceTable.Id_shoping, ResourceTable.Id_community, ResourceTable.Id_my})
    public void click(Component component) {
        System.err.println(component.getId() + "::::::::::::::::::::::");
        switch (component.getId()) {
            case ResourceTable.Id_home:
                setUI(new HomeSlice(), home);
                break;
            case ResourceTable.Id_classly:
                setUI(new ClasslySlice(), classly);
                break;
            case ResourceTable.Id_shoping:
                setUI(new ShopingSlice(), shoping);
                break;
            case ResourceTable.Id_community:
                setUI(new CommunitySlice(), community);
                break;
            case ResourceTable.Id_my:
                setUI(new MySlice(), my);
                break;

        }
    }

    public void setUI(Fraction fraction, Text textview) {
        //清空文字颜色
        setTextColor(textview);
        dl_frame.removeAllComponents();
        //加载界面
        ((FractionAbility) getAbility()).getFractionManager().startFractionScheduler().add(ResourceTable.Id_dl_frame, fraction).submit();
    }


    //单个Item切换
    public void setTextColor(Text textview) {
        ResourceManager resourceManager = getAbility().getResourceManager();
        Resource resource;
        PixelMapElement element;
        try {
            int color = resourceManager.getElement(ResourceTable.Color_color_d0).getColor();
            int color2 = resourceManager.getElement(ResourceTable.Color_color_f3).getColor();
            clearClick(color);//清除点击事件
            textview.setTextColor(new Color(color2));
            if (textview == home) {//首页
                resource = resourceManager.getResource(ResourceTable.Media_home1);
                element = new PixelMapElement(resource);
                home.setAroundElements(null, element, null, null);

            } else if (textview == classly) {//分类
                resource = resourceManager.getResource(ResourceTable.Media_fenlei1);
                element = new PixelMapElement(resource);
                classly.setAroundElements(null, element, null, null);

            } else if (textview == community) {//社区
                resource = resourceManager.getResource(ResourceTable.Media_sq1);
                element = new PixelMapElement(resource);
                community.setAroundElements(null, element, null, null);

            } else if (textview == shoping) {//购物车
                resource = resourceManager.getResource(ResourceTable.Media_gwc1);
                element = new PixelMapElement(resource);
                shoping.setAroundElements(null, element, null, null);
            } else if (textview == my) {//我的
                resource = resourceManager.getResource(ResourceTable.Media_my1);
                element = new PixelMapElement(resource);
                my.setAroundElements(null, element, null, null);
            }


        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //清空点击事件
    public void clearClick(int color1) {
        ResourceManager resourceManager = getAbility().getResourceManager();
        Resource resource;
        PixelMapElement element;
        try {
            resource = resourceManager.getResource(ResourceTable.Media_home);
            element = new PixelMapElement(resource);
            home.setAroundElements(null, element, null, null);
            home.setTextColor(new Color(color1));

            resource = resourceManager.getResource(ResourceTable.Media_fenlei);
            element = new PixelMapElement(resource);
            classly.setAroundElements(null, element, null, null);
            classly.setTextColor(new Color(color1));

            resource = resourceManager.getResource(ResourceTable.Media_sq);
            element = new PixelMapElement(resource);
            community.setAroundElements(null, element, null, null);
            community.setTextColor(new Color(color1));

            resource = resourceManager.getResource(ResourceTable.Media_gwc);
            element = new PixelMapElement(resource);
            shoping.setAroundElements(null, element, null, null);
            shoping.setTextColor(new Color(color1));

            resource = resourceManager.getResource(ResourceTable.Media_my);
            element = new PixelMapElement(resource);
            my.setAroundElements(null, element, null, null);
            my.setTextColor(new Color(color1));
        } catch (Exception e) {
            e.printStackTrace();
        }

    }

    //回退拦截
    @Override
    protected void onBackPressed() {
        //弹出提示框
        CommonDialog commonDialog = new CommonDialog(getContext());
        DirectionalLayout toastLayout = (DirectionalLayout) LayoutScatter.getInstance(getContext())
                .parse(ResourceTable.Layout_layout_dialog, null, false);
        commonDialog.setContentCustomComponent(toastLayout);
        //退出应用
        Button dialog_out = (Button)toastLayout.findComponentById(ResourceTable.Id_dialog_out);
        dialog_out.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                commonDialog.hide();
                terminateAbility();
            }
        });
        //隐藏
        Button dialog_hide = (Button)toastLayout.findComponentById(ResourceTable.Id_dialog_hide);
        dialog_hide.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                commonDialog.hide();

            }
        });
        //再听听
        Button dialog_continue = (Button)toastLayout.findComponentById(ResourceTable.Id_dialog_continue);
        dialog_continue.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                commonDialog.hide();
            }
        });
        commonDialog.setSize(800,410);
        commonDialog.setAlignment(LayoutAlignment.CENTER);
        commonDialog.show();
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}

分享
微博
QQ
微信
回复
2021-01-18 17:36:26
破茧_追梦

就这些就可以实现了,我的这个写的比较乱

分享
微博
QQ
微信
回复5
2021-01-18 17:37:55
相关问题
应用侧显示华为云mqtt数据是怎么做
3278浏览 • 1回复 待解决
PageAbility配合多个Slice实现页面切换
8616浏览 • 4回复 已解决
工具类里 怎么跳转或打开页面?
387浏览 • 1回复 待解决
鸿蒙tablist 如何通过滑动切换页面
1765浏览 • 1回复 待解决
java鸿蒙Tab框架 image图片怎么渲染
2296浏览 • 2回复 待解决
服务卡片如何跳转到指定页面
1387浏览 • 1回复 待解决
鸿蒙demo gradle报错怎么解决
5654浏览 • 4回复 待解决
JS如开发一个横向拖动表格
2246浏览 • 1回复 待解决
ScrollView嵌套ListContainer
2282浏览 • 5回复 待解决
页面之间跳转方式怎么设置
1812浏览 • 1回复 待解决
华为能不能做个快捷指令?
3749浏览 • 1回复 待解决
鸿蒙请求相册和相机demo
991浏览 • 1回复 待解决