나는 거의 모든 내 활동에 사이드 메뉴가있는 안드로이드 애플 리케이션을 가지고있다. 이를 위해 서랍 레이아웃과 일관된 UI를위한 몇 가지 다른 항목이있는 xml 활동을 수행해야합니다. 예를안드로이드 XML에서 코드 중복을 피하는 방법
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<include layout="@layout/toolbar"
android:id="@+id/toolbar_container"/>
<<--ACTIVITY_XML-->>
</RelativeLayout>
</android.support.v4.widget.DrawerLayout>
를 들어 또 다시 코드를 복사 할 수있는 방법이 있습니까.
내가 편도로 생각하면, <<--ACTIVITY_XML-->>
을 포함 태그로 바꾸십시오. 그럼 내 기본 활동에서 setContentView()
을 오버라이드하고, 위에서 언급 한 기본 레이아웃을 부 풀린 다음 내부에 포함 태그를 부 풀린다. 메모리와 시간 활용면에서이 방법이 좋든 나쁨이든.
include 및 merge 태그에서 모두 검색 더 나은 최적화를 위해 모두 사용 –
공통 UI 요소와 서랍이있는 기본 컨테이너로 1 활동을 사용할 수 있으며 그 활동에서 단편 대체를 사용하는 것이 좋습니다. – Yazan