Android - 合并和包含

时间:2015-02-12 11:33:35

标签: android

我想在我的应用中使用切换按钮。由于其API为11且交换机需要API高于14,我决定使用mergeinclude方法,但我在values-v14/compound_switch.xml文件中收到此错误:Element merge must be declerd。这是我的文件,有什么问题?

主要布局:

<include layout="@layout/compound_switch" />

布局/ compound_switch.xml

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

<CheckBox
    android:id="@+id/night_switch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView20"
    android:layout_toLeftOf="@+id/textView20"
    android:layout_toStartOf="@+id/textView20"
    android:layout_marginRight="5dp"
    android:checked="false" />

</merge>

值-V14 / compound_switch.xml

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

<Switch
    android:id="@+id/night_switch"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignTop="@+id/textView20"
    android:layout_toLeftOf="@+id/textView20"
    android:layout_toStartOf="@+id/textView20"
    android:layout_marginRight="5dp" />

</merge>

1 个答案:

答案 0 :(得分:0)

将包含切换的布局从文件夹values-v14移动到名为layout-v14的文件夹。布局应位于layout文件夹中。 values文件夹用于颜色,尺寸,属性等。