[英]How to use same XML layout in android to create several activities, each with their own custom view
Android编码的新手,但是我找不到这个特定问题的答案。 说我有以下XML布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<view class="com.example.testapp.customView"
android:id="@+id/drawView"
android:layout_height="100dp"
android:layout_width="fill_parent" />
<Button android:id="@+id/bNormal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:text="Update" />
</LinearLayout>
我想使用这种布局来创建多个活动,但是在每个活动中我都想使用不同的customView。 例如。 对于一个活动,我希望自定义视图为customView1,对于第二个活动,我希望其为customView2,依此类推。
我将如何去做? 现在,我的每个活动都只有一个单独的XML布局,这似乎非常多余。
您要么创建多个布局,要么必须以编程方式添加新视图(通过创建适当类型的对象并将其添加到父视图),而不是通过xml来完成。 xml布局背后的想法是您的布局或多或少是静态的,因此xml精确地指定了您想要的内容。 它本身并不是要改变一切的编程语言。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.