作为 android 中另一个布局的子集的布局
Layout as a subset of another layout in android
我在 XML 中构建了这样的布局,比如 "block.xml"
现在,我想创建一个像这样的 XML
这样我就可以将每个块作为数组访问。有人能告诉我如何使用 block.xml 作为模板来生成我的新 xml 文件,并将其作为 UI 的一部分放入 android 中。谢谢
为了确定,我想使用 table 布局,但我不知道如何进行。
您应该以编程方式扩充和添加子布局。
这个link有示例代码:
Android using layouts as a template for creating multiple layout instances
在您的布局中 xml 您可以使用包含标签并重新使用您的 block.xml
如:
<include
android:id="@+id/block1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/block" />
并且在您的 java 代码中,您可以从 block.xml 作为
访问视图
View firstBlock = findViewById( R.id.block1 );
View blockButton = firstBlock.findViewById( R.id.someButtonId );
我在 XML 中构建了这样的布局,比如 "block.xml"
现在,我想创建一个像这样的 XML
这样我就可以将每个块作为数组访问。有人能告诉我如何使用 block.xml 作为模板来生成我的新 xml 文件,并将其作为 UI 的一部分放入 android 中。谢谢
为了确定,我想使用 table 布局,但我不知道如何进行。
您应该以编程方式扩充和添加子布局。
这个link有示例代码: Android using layouts as a template for creating multiple layout instances
在您的布局中 xml 您可以使用包含标签并重新使用您的 block.xml
如:
<include
android:id="@+id/block1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
layout="@layout/block" />
并且在您的 java 代码中,您可以从 block.xml 作为
访问视图View firstBlock = findViewById( R.id.block1 );
View blockButton = firstBlock.findViewById( R.id.someButtonId );