相关疑难解决方法(0)

设置包含布局的子元素的属性

我有一个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>
Run Code Online (Sandbox Code Playgroud)

及其包含的布局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>
Run Code Online (Sandbox Code Playgroud)

我只想在我的主布局中包含5次"mylayout",但是我没有看到"hello world"5次,而是希望TextView包含自定义文本.

有没有办法通过在include元素上设置一些属性来覆盖子TextView的文本?实现这一目标的最佳方法是什么?

android android-widget android-layout

40
推荐指数
3
解决办法
1万
查看次数

标签 统计

android ×1

android-layout ×1

android-widget ×1