android - 覆盖 xml <include .../>

标签 android xml android-layout

是否可以在标签中覆盖 xml 中的属性?

父级.xml

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >
    <include  
        layout="@layout/button"
         android:text="HAHAHAH"
         />
</TableLayout>

按钮.xml:

    <?xml version="1.0" encoding="utf-8"?>
   <TextView  xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="some string" />

是否可以将“某个字符串”更改为“哈哈哈”?

最佳答案

是和否:)"is",因为您通常可以覆盖 XML 中的属性,“否”是因为在这种情况下,只有更改 android:layout_* 属性才会生效:

You can also override all the layout parameters (any android:layout_* attributes) of the included layout's root view by specifying them in the tag. For example:

<include android:id=”@+id/news_title”
         android:layout_width=”match_parent”
         android:layout_height=”match_parent”
         layout=”@layout/title”/>

However, if you want to override layout attributes using the tag, you must override both android:layout_height and android:layout_width in order for other layout attributes to take effect.

http://developer.android.com/training/improving-layouts/reusing-layouts.html#Include

关于android - 覆盖 xml <include .../>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14127666/

相关文章:

安卓多语言应用

Android如何检查 Intent 服务是否仍在运行或已停止运行

android - 我可以隐藏多余的系统日志吗?

ruby - 使用 savon 的 SOAP 消息标记名称中的大小写问题

android - @id 和@+id 有什么区别?

android - 如何调整recyclerview高度?

Android 应用链接不适用于 Chrome 自定义标签

java - Android camera : Threads? 哪个应该做什么

xml - 使用XPath根据我创建的XML模式从XML文件检索信息

android - 广告加载期间的布局问题