如何在代码而不是 XML 中动态地执行此操作?
我想在我的代码中动态定义以下布局(当前是一个 xml 文件)。
最终目标是能够有条件地将某些页面包含在我的视图翻转器中。
谢谢!
<?xml version="1.0" encoding="utf-8"?>
<com.gtosoft.dash.MyViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Page 01 -->
<include android:id="@+id/flipperPage01" layout="@layout/page01" />
<!-- Page 02 -->
<include android:id="@+id/flipperPage02" layout="@layout/page02" />
<!-- Page 03 -->
<include android:id="@+id/flipperPage03" layout="@layout/page03" />
</com.gtosoft.dash.MyViewFlipper>
I would like to define the following layout (which is currently an xml file) dynamically in my code.
The end goal is to have the ability to conditionally include certain pages in my viewflipper.
Thanks!
<?xml version="1.0" encoding="utf-8"?>
<com.gtosoft.dash.MyViewFlipper
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/vFlipper"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<!-- Page 01 -->
<include android:id="@+id/flipperPage01" layout="@layout/page01" />
<!-- Page 02 -->
<include android:id="@+id/flipperPage02" layout="@layout/page02" />
<!-- Page 03 -->
<include android:id="@+id/flipperPage03" layout="@layout/page03" />
</com.gtosoft.dash.MyViewFlipper>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 LayoutInflater 并将元素动态添加到自定义视图中。另请参阅这篇文章:从布局查看
You can use LayoutInflater and add elements dynamically to your custom view. Also see this post: view from layout