programing

Android XML 레이아웃의 간단한 예제 및 사용법

oldcodes 2023. 9. 26. 22:31
반응형

Android XML 레이아웃간단한 예제 및 사용법

궁금합니다.<merge>그리고.<include>Android XML 레이아웃의 태그입니다.두 개의 튜토리얼을 읽었지만 아직 간단한 사용 예시를 찾지 못했습니다.

누군가가 그러한 예를 제시하거나 예를 들어줄 수 있다면 기쁠 것입니다.

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>

예를 들어,

태그가 두 개 있습니다.<EditText>그리고.<ListView >둘 이상의 UI를 제공합니다. 그래서 아래와 같이 XML 파일을 만들어 모든 UI에 포함시켰습니다.

<?xml ...>
<EditText ... />
<ListView ... />   

위 XML에 루트 요소가 없으므로 유효한 XML이 아닙니다.서 XML합니다를 합니다.<merge>입니다.

<?xml ...>
<merge xmlns:android="http://schemas.android.com/apk/res/android">
    <EditText ... />
    <ListView ... />
</merge>

간단한 Android XML 레이아웃 <include /> HOWTO>는 http://www.coboltforge.com/2012/05/tech-stuff-layout/ 에서 흔히 볼 수 있는 문제점도 설명하고 있습니다.그게 도움이 될지도...

<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>

예제_ layout.xml(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>

를 볼 수 .enter image description here

id가 코드를 붙여넣지 않았다면 상대적인 레이아웃 매개변수가 작동했을 것입니다.몇 가지 다른 처리를 합니다.

언급URL : https://stackoverflow.com/questions/2732682/simple-example-of-merge-and-include-usage-in-android-xml-layouts

반응형