간단한 예 과 Android XML 레이아웃에서의 사용법
Android XML 레이아웃 의 <merge>
및 <include>
태그가 궁금합니다 . 두 개의 튜토리얼을 읽었지만 아직 간단한 예제 사용법을 찾지 못했습니다.
누군가가 그러한 예를 제공하거나 하나에 대한 지침을 줄 수 있다면 행복 할 것입니다.
some_activity.xml :
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:orientation="vertical">
// some views
<include layout="@layout/view_part"/>
// probably more views
</LinearLayout>
view_part.xml :
<merge xmlns:android="http://schemas.android.com/apk/res/android">
// the views to be merged
</merge>
http://www.coboltforge.com/2012/05/tech-stuff-layout/ 에는 일반적인 함정을 설명하는 간단한 Android XML 레이아웃 <include /> HOWTO가 있습니다 . 도움이 될 수 있습니다 ...
예를 들어 보자 :
두 개의 태그가 <EditText>
있고 두 <ListView >
개 이상의 UI가 제공됩니다. 그래서 이러한 모든 UI에 포함하기 위해 아래와 같이 XML 파일을 만들었습니다.
<?xml ...>
<EditText ... />
<ListView ... />
위의 XML은 루트 요소가 없기 때문에 유효한 XML이 아닙니다. 따라서 XML을 위해 루트 요소가 필요합니다. <merge>
아래에 주어진 해결책입니다.
<?xml ...>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
<EditText ... />
<ListView ... />
</merge>
id는 코드를 붙여 넣지 않습니다. 그렇지 않으면 상대 레이아웃 매개 변수가 작동했을 것입니다. 다른 처리를합니다.
<merge>
태그는 렌더링 레이아웃의 성능을 높이기 위해 레벨 수를 줄이는 데 사용됩니다. 태그는 태그와 <include>
완벽하게 함께 사용 됩니다.
예를 들어, 로그인 레이아웃이 있고 앱 범위에서 둘 이상에 사용됩니다. login_layout을 표시하기 위해 태그를 사용하는 동안 우리는 레벨을 사용하고 이스케이프 할 수 있습니다.
또한 레이아웃에 대한 트릭을 읽어 보는 것이 좋습니다. http://android-developers.blogspot.com.tr/2009/03/android-layout-tricks-3-optimize-by.html
login_form.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- Login form -->
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Email..."
android:inputType="textEmailAddress"
android:maxLines="1"
android:singleLine="true"
android:visibility="visible" />
<EditText
android:id="@+id/password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password.."
android:imeActionId="@+id/login"
android:imeOptions="actionUnspecified"
android:inputType="textPassword"
android:maxLines="1"
android:singleLine="true"
android:text="1337"
android:visibility="visible" />
<Button
android:id="@+id/sign_in_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="16sp"
android:paddingLeft="32sp"
android:paddingRight="32sp"
android:text="Login"
android:visibility="visible" />
</LinearLayout>
example_layout.xml (any layout we want to include login_form.xml)
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" >
<include layout="@layout/login_form" />
</merge>
We can see the level hierarchy
'Program Tip' 카테고리의 다른 글
C ++ 멤버 함수에서 "if (! this)"는 얼마나 나쁩니 까? (0) | 2020.10.24 |
---|---|
int는 항상 0으로 초기화됩니까? (0) | 2020.10.24 |
GCD의 블록 내에 NSAutoreleasePool을 만들어야합니까? (0) | 2020.10.24 |
UTF-8 인코딩 문자의 최대 바이트 수는 얼마입니까? (0) | 2020.10.24 |
웹팩을 사용하여 디렉토리에서 동적으로 이미지 가져 오기 (0) | 2020.10.24 |