是否可以在标签中覆盖 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/