【发布时间】:2012-02-19 06:17:08
【问题描述】:
我有一个描述主要活动布局的 main.xml 文件:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
<include layout="@layout/mylayout" />
</LinearLayout>
及其包含的布局xml文件(mylayout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/mylayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hello world" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
我只想在我的主布局中包含 5 次“mylayout”,但不是看到 5 次“hello world”,而是希望 TextView 包含自定义文本。
有没有办法通过在 include 元素上设置一些属性来覆盖子 TextView 的文本?实现这一目标的最佳方法是什么?
【问题讨论】:
-
这似乎是一个应该修复的严重限制。我刚刚提交了bug report。
标签: android android-layout android-widget