android - 重用布局及其子组件
问题描述
我查看了 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.xml
,layout2.xml
我想在其中使用标签重用这个布局include
,但我想做以下事情,这在文档中没有提到:
根
LinearLayout
可以被赋予不同的,但是,在我在和中包含(使用)这个布局之后,我id
如何给id
两者赋予不同的ImageView
TextView
<include ..>
layout1.xml
layout2.xml
如果我希望在
ImageView
中包含不同的图像,layout1.xml
如何layout2.xml
使用<include ...>
标签更改此属性?
解决方案
推荐阅读
- php - 将 php 文件回显到模式中的模式中 | PHP
- python - 在file.txt python3上搜索特定字符串
- eclipse - eclipse 项目构建路径让我发疯
- python - 无法在 Django 管理中选择多对多,因为右侧选择窗格不可见
- reactjs - 使用 aws-api s3.upload 在文件位置出现 403 错误
- asp.net - ASP.NET Framework 无法获取对另一个模型的引用
- javascript - 倒数计时器不循环工作和休息时间
- python - Python Networkx - 根据不同的中心性度量为节点着色
- javascript - 从谷歌金融获取股票价格到网页
- javascript - 一个接一个地动画 div 高度 onload javascript