首页 > 解决方案 > 重用布局及其子组件

问题描述

我查看了 android docs,但它没有给您任何关于如何使用 xml 覆盖子组件属性的提示(也没有以编程方式,xml但我现在更喜欢)。

考虑以下名为 的布局layoutBase.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/titlebar_bg"
    tools:showIn="@layout/activity_main" >

    <ImageView 
               android:id="@+id/myImageViewBase"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:src="@drawable/gafricalogo" />
    <TextView
               android:id="@+id/myTextViewBase"
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"/>

</LinearLayout>  

现在,我调用了另外两个布局layout1.xmllayout2.xml我想在其中使用标签重用这个布局include,但我想做以下事情,这在文档中没有提到

标签: androidxmlandroid-studiolayout

解决方案


推荐阅读