如何在页面或布局中动态添加视图 [英] How to dynamically add view in page or layout

查看:184
本文介绍了如何在页面或布局中动态添加视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何以编程方式将视图添加到布局或页面中.

I can't figure out how to programatically add a view into a layout or page.

我需要在运行时添加视图,而无需使用静态xml声明,因为我需要从http请求的对象中获取视图....我没有在文档中找到有用的信息.

I need to add views at runtime without using static xml declaration since i need to fetch them from an http requested object... . I didn't find useful informations in the docs.

有人知道怎么做吗?

推荐答案

我认为您的意思是向页面动态添加一些视图/控件,而不是导航到另一个页面. 如果是这样,您只需要向页面的一种布局中添加一些控件即可(只有容器[= layouts]可以有多个子代.

I think you meant to dynamically add some view / controls to the page rather than to navigate into another page. If so, you just need to add some controls into one of the layouts in your page (only containers [=layouts] can have multiple children.

so, your code (viewmodel/page controller) would look something like:
var layout = page.getViewById("Mycontainer");
// create dynamic content
var label = new Label();
label.text = "dynamic";
// connect to live view
layout.addChild(label)

这篇关于如何在页面或布局中动态添加视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆