및 <merge>
을 올바르게 사용할 수 있는지 이해할 수 있는지 알려주는 사람이 필요합니다.<include> 및 <merge>
그래서, 내가 다른 XML 레이아웃에 포함 할 헤더 레이아웃합니다
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header text" />
</LinearLayout>
을 그리고 난 다른 XML로 (아주 기본입니다)이 방법을 포함한다 :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<include android:id="@+id/header" layout="@layout/top"
android:layout_width="fill_parent" android:layout_height="wrap_content"
/>
</LinearLayout>
을
문제없이 작동합니다. 그러나 코드를 최적화하기 위해 포함 된 레이아웃에서 <merge>
을 사용해야합니다. 그래서 top layout
는 태그 <LinearLayout>
가 없어야하지만, 다음과 같이해야합니다
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Header text" />
</merge>
내가이 올바르게 이해 적이 있습니까?
예. 좋아요. 내 경험에 의하면, 나는 병합 할 필요가 없다. 필자는 텍스트 뷰를 자체 XML 파일에 배치하고 해당 파일을 포함 할 수 없습니다. 병합 할 필요가 없습니다. – AedonEtLIRA
예, 작동하지만 Google 개발자가 그러한 연습을 제안하지 않았기 때문에 ** 그렇게 사용하는 것이 안전합니다 **. 병합 태그를 인식하는 무언가를 변경하기로 결정하면 어떻게 될지 걱정됩니다. – sandalone
@sandalone 여러분은 XML을 새로운 표준으로 업데이트해야 할 모든 것을 좋아합니다. 처음부터 안드로이드에서 많은 감가 상각 된 메소드가 있었기 때문에 이것은 염두에 두어야 할 것이지만 실제로는 문제가 아닙니다. – Jonny2Plates