Resource-Switching in Android
  Application은 다른 device configuration에 customize된 다수의 resource를 포함할 수 있다. 사용자가 Application을 실행할 때 안드로이드는 자동으로 device에 가장 적합한 resource를 선택하여 로드한다.
Application이 locale-specific text을 제공하지 않는 locale에서 실행된다면, 안드로이드는 default string(/res/values/string.xml)을 로드한다. 만일 locale에 해당하는 text와 default text가 모두 제공되지 않으면 Application은 실행하지 않고 에러를 보여주게 된다.
따라서 Application이 사용하는 모든 resource를 포함하는 default resource를 만들 필요가 있다.
default resource란 /res directory 아래에 있는 values, drawable, layout, anim, xml,raw directory 등을 말한다.

Application을 localizing하는 가장 큰 부분은 다른 언어에 대한 Alternate Text를 제공하는 것이다. 필요에 따라서는 graphic, sounds, layout 등 다른 resource도 제공할 필요가 있을 것이다.
다른 locale에 alternate resource를 제공하기 위해 언어별 또는 언어-지역 별로 특화된 qualifier를 사용한다.
예를 들어 res/values/string.xml을 default로 사용하고 French Text는 /res/values-fr/string.xml, 그리고 japan Text는 /res/values-ja/string.xml에 저장한다고 가정하면, device의 language가 french나 japan이 아닌 경우는 /res/values/string.xml을 사용하고 , device에 French가 설정되어 있으면 /res/values-fr/string.xml을 사용하게 된다.
만일 device에 설정된 language에 해당하는 resource가 없을 경우 안드로이드는 default resource를 참조하게 된다.
 
Device configuration에 일치하는 여러개의 resource가 있는 경우 안드로이드는 여거 qualifier 중에서 locale을 우선으로 한다. 단 locale 보다 MCC와 MNC가 우선시 된다.

Tip: locale 정보가 있는 resource를 소스코드 내에서 참조하는 경우에도 default resource를 참조하듯이 사용하며 별도의 locale 정보를 참조하지는 않는다. 다만 해당 resource에 대해 안드로이드에서 locale이 있는 경우는 해당 resource를 사용하고 그렇지 않은 경우는 default를 사용하게 되는 것이다.

Localization Strategies
  기본적으로 default resource를 가지도록 Application을 설계한다.
1. Design a flexable layout
  특정 언어에 맞는 Layout을 재배역할 필요가 있다면 alternate layout을 사용하면 된다. 하지만 이렇게 하면 유지보수가 어려워지기 때문에 좀더 flexable한 single layout을 고려해야 한다.
또한 하나의 layout에 서로 다른 언어가 필요한 상황이 있을 수 있다.
이러한 사항을 다루기위해 다음과 같은 두가지의 방법이 있는데...
  1) 프로그램적으로 Source Code에서 언어에 기초하여 enable or disable할 수 있는 필드를 layout에 생성하는 방법
  2) 변경가능한 필드를 가진 또 다른 layout(sub layout이라고 표현하면 좋을 듯)을 포함한 main layout을 생성하는 방법이 있으며, sub layout은 언어에 따라 다른 configuration을 갖도록 하는 것이다.

2. 필요한 resource에 대해서만 alternate resource를 생성한다.
3. 프로그램에서 locale을 확인하는 방법은 아래돠 같다.
String locale = context.getResources().getConfiguration().locale.getDisplayName();
 
Testing Localized Applications
  단말에서 locale을 변경하는 방법은 Home > Menu > Settings > Locale & text > Select locale을 통해 가능하다.

Publishing Localized Applications
  Android Market에서 localized applicaiton을 배포하기 위해서는 application을 sign하고, versioning한 후 이 후 과정을 진행한다.

Localization Checklists
  기본적이 Checklist는 개발 가이드를 참조한다.



Posted by 피의복수

Simple Values
  Simple resource values는 resource의 타입이 명확한 포맷을 사용하며, string 처럼 표현된다. 따라서 표준 resource(/res/values/)로 정의되고, style 및 theme에 매핑한다거나, layout 과 같이 XML의 attribute로 사용되기도 한다.
Simple values에는 다음과 같은 종류가 있다.
1. Color Values
 
Alpha Channel을 가진 RGB를 사용한다.
Color Value는 #으로 시작하고 다음 포맷 중의 하나를 사용한다. (#RGB, #ARGB, #RRGGBB, #AARRGGBB)

Location: res/values/colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <color name="opaque_red">#f00</color>
   <color name="translucent_red">#80ff0000</color>
</resources>

Source Code에서 사용하기
// Retrieve a color value.
int color = getResources.getColor(R.color.opaque_red);

XML에서 사용하기
<TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAlign="center"
          android:textColor="@color/translucent_red"
          android:text="Some Text"/>

2. Strings 
  String도 Resource로 저장되고 조회될 수 씨는데 <b>, <i>, <u> 와 같은 표준 HTML Tag를 사용하여 정의할 수도 있다.

Location: res/values/strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>
   <string name="simple_welcome_message">Welcome!</string>
   <string name="styled_welcome_message">We are <b><i>so</i></b> glad to see you.</string>
</resources>

Source Code에서 사용하기
// Assign a styled string resource to a TextView
// on the current screen.
CharSequence str = getString(R.string.styled_welcome_message);
TextView tv = (TextView)findViewByID(R.id.text);
tv.setText(str);

XML에서 사용하기
<TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAlign="center"
          android:text="@string/simple_welcome_message"/>

Note: quote나 apostrophe를 사용하는 경우 escape 사용하거나 다른 quote로 전체 string을 닫아주어야 한다.
<string name="good_example">"This'll work"</string>
<string name="good_example_2">This\'ll also work</string>

3. Styled Text as a Format Strings
  Styled Text을 사용하는 방법은 escaped HTML tag로 style tag를 저장한 후 formating 루 다시 styled text로 변경하는 방법을 사용하면 된다.
1) escaped string으로 styled text resource를 저장한다.
<resources>
  <string name="search_results_resultsTextFormat">%1$d results for &lt;b>&amp;quot;%2$s&amp;quot;&lt;/b></string>
</resources>

2) htmlEncode() method를 통해 escaped 되었는지 확인한다.
String escapedTitle = TextUtil.htmlEncode(title);

3) HTML Text를 formattig하기 위해 String.format() method를 사용한다. 그 후 HTML을 styled text로 변환하기 위해 fromHTML() method를 사용한다.
String resultsTextFormat = getContext().getResources().getString(R.string.search_results_resultsTextFormat);
String resultsText = String.format(resultsTextFormat, count, escapedTitle);
CharSequence styledResults = Html.fromHtml(resultsText);

4. Dimensions
  XML에 dimension value를 정의함으로써 다양한 screen elements에서 사용되는 dimension을 생성할 수 있다.
안드로이드에서 지원하는 측정 단위는 다음과 같다.

px(Pixels): 실제 screen pixel
in(Inches): screen의 물리적 사이즈 기준
mm(Milimeters): screen의 물리적 사이즈 기준
pt(Points): screen의 물리적 사이즈에 기준한 inch의 1/72
dp(Density-independent Pixels): screen의 물리적 밀도에 기준한 추상적 단위.
sp(Scale-independent Pixels): dp와 유사하지만 사용자 폰트 사이즈 설정에 따른다.

Dimension value는 일반적으로 raw resource에서 사용되지 않고 XML의 attribute로서 사용된다.

Location: res/values/dimens.xml

<resources>
    <dimen name="one_pixel">1px</dimen>
    <dimen name="double_density">2dp</dimen>
    <dimen name="sixteen_sp">16sp</dimen>
</resources>

Source Code에서 사용하기
float dimen = Resources.getDimen(R.dimen.one_pixel);

XML에서 사용하기
<TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textSize="@dimen/sixteen_sp"/>


Drawables
  Drawable 은 screen에 draw하기 위해 사용되는 resource type이다.

1. Bitmap Files
  안드로이드는 약간 다른 포맷인 png, jpg, gif 포맷으로 bitmap resource file을 지원한다.bitmap file은 그 자체가 compile되고 확장자 없이 파일명으로만 참조된다.

Location: /res/drawable/my_image.png

Source Code에서 사용하기
Resources res = mContext.getResources();
Drawable myImage = res.getDrawable(R.drawable.my_image);

XML에서 사용하기
<ImageView  
  android:layout_width="wrap_content"
  android:layout_height="wrap_content"
  android:tint="#55ff0000"
  android:src="@drawable/my_image"/>

2. Color Drawables
  color를 가진 사각형인 PaintDrawable object를 생성할 수도 있다.

Location: res/values/colors.xml

<resources>
    <drawable name="solid_red">#f00</drawable>
    <drawable name="solid_blue">#0000ff</drawable>
    <drawable name="solid_green">#f0f0</drawable>
</resources>

Source Code 에서 사용하기
// Assign a PaintDrawable as the background to
// a TextView on the current screen.
Drawable redDrawable = Resources.getDrawable(R.drawable.solid_red);
TextView tv = (TextView)findViewByID(R.id.text);
tv.setBackground(redDrawable);

XML에서 사용하기
<TextView android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:textAlign="center"
          android:background="@drawable/solid_red"/>


3. Nine-Patch (stretchable) Images
  안드로이드는 NinePatch graphic이라고 부르는 stretchable bitmap image를 지원한다. Stretchable Image란 stretchable section에 정의하는 PNG Image를 말한다. Stretchable Section은, text String 처럼 출력시 object를 가변 사이즈에 수용하지 위해 안드로이드가 resize하는 공간을 말한다.(?)

Location: res/drawable/some_name.9.png
Tip: 반드시 파일이름은 xxxx.9.png 로 끝나야 한다.

XML에서 사용하기

<Button id="@+id/tiny"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerInParent="true"
        android:text="Tiny"
        android:textSize="8sp"
        android:background="@drawable/my_button_background"/>

<Button id="@+id/big"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerInParent="true"
        android:text="Biiiiiiig text!"
        android:textSize="30sp"
        android:background="@drawable/my_button_background"/>

Animation
  안드로이드는 하나의 graphic 또는 일련의 graphics 위에 간단한 anumation을 실행할 수 있으며, rotation, fading, moving 그리고 stretching을 포함한다.

Location: res/anim/some_file.xml

<set android:shareInterpolator=boolean>  // Only required if multiple tags are used.
   <alpha android:fromAlpha=float
          android:toAlpha=float >   |
   <scale android:fromXScale=float
          android:toXScale=float
          android:fromYScale=float
          android:toYScale=float
          android:pivotX=string
          android:pivotY=string >    |
   <translate android:fromX=string
              android:toX=string
              android:fromY=string
              android:toY=string >   |
   <rotate android:fromDegrees=float
           android:toDegrees=float
           android:pivotX=string
           android:pivotY=string > |
   <interpolator tag>
   <set>
</set>

XML의 모든 element는 동시에 적용되므로 순차적으로 진행하기 위해서는 startOffset attribute를 사용하여야 한다.
각각의 attribute에 해당하는 자세한 내용은 안드로이드 가이드를 참조하기 바란다.

Menus
  이전에도 언급한 내용으로 안드로이드 메뉴는 Options Menu, Context Menu와 Sub Menu이며 이들은 XML에 resource로 정의될 수 있으며, 소스 코드 내에서 MenuInflater를 사용하여 나타난다.

Location: res/menu/some_file.xml

<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/example_item
          android:title="Example Item"
          android:icon="@drawable/example_item_icon" />
    <group android:id="@+id/example_group">
        <item android:id="@+id/example_item2
              android:title="Example Item 2"
              android:icon="@drawable/example_item2_icon" />
    </group>
    <item android:id="@+id/example_submenu
          android:title="Example Sub Menu" >
        <menu>
            <item android:id="@+id/example_submenu_item
                  android:title="Example Sub Menu Item" />
        </menu>
    </item>
</menu>

Layout
  이전에 설명했던 내용을 참조하기 바란다.

Styles and Themes
  이전에 설명했던 내용을 참조하기 바란다.

Searchable
  사용자에게 검색을 나타나게 하기 위해 안드로이드 Framework은 Application이 검색방식을 제어할 수 있도록 API를 제공한다.

Location: res/xml/searchable.xml

<searchable xmlns:android="http://schemas.android.com/apk/res/android
     android:label="@string/search_label"
     ... >
     <actionkey
          android:keycode="KEYCODE_CALL"
          ... >    
</searchable>


각각의 attribute에 해당하는 자세한 내용은 안드로이드 가이드를 참조하기 바란다.

Posted by 피의복수

Resource란 소스 코드에서 사용되고 빌드 시 Application으로 Compile되는 외부 파일(소스가 아닌 파일)들을 말한다.
안드로이드는 다양한 종류의 resource file을 지원하는데, XML, PNG 그리고 JPG등이 있다.

Creating Resources
안드로이드는 string, bitmap과 다양한 종류의 resource를 지원한다. 각각의 syntac와 format, 그리고 저장되어 있는 장소는 object의 타입에 따라 달라지게 된다. 하지만 일반적으로 다음과 같은 3가지의 타입으로 resource를 생성할 수 있는데, XML, bitmap(for images) 그리고 raw file(sound file 등)으로 볼 수 있다.

다음은 각 resource 별 파일 타입을 나타낸다.
Directory Resource Types
res/anim/ XML files that are compiled into frame by frame animation or tweened animation objects
res/drawable/

.png, .9.png, .jpg files that are compiled into the following Drawable resource subtypes:

To get a resource of this type, use mContext.getResources().getDrawable(R.drawable.imageId)

Note: Image resources placed in here may be automatically optimized with lossless image compression by the aapt tool. For example, a true-color PNG that does not require more than 256 colors may be converted to an 8-bit PNG with a color palette. This will result in an image of equal quality but which requires less memory. So be aware that the image binaries placed in this directory can change during the build. If you plan on reading an image as a bit stream in order to convert it to a bitmap, put your images in the res/raw/ folder instead, where they will not be optimized.

res/layout/ XML files that are compiled into screen layouts (or part of a screen). See Declaring Layout.
res/values/

XML files that can be compiled into many kinds of resource.

Note: Unlike the other res/ folders, this one can hold any number of files that hold descriptions of resources to create rather than the resources themselves. The XML element types control where these resources are placed under the R class.

While the files can be named anything, these are the typical files in this folder (the convention is to name the file after the type of elements defined within):

  • arrays.xml to define arrays
  • colors.xml to define color drawables and color string values. Use Resources.getDrawable() and Resources.getColor(), respectively, to get these resources.
  • dimens.xml to define dimension value. Use Resources.getDimension() to get these resources.
  • strings.xml to define string values (use either Resources.getString or preferably Resources.getText() to get these resources. getText() will retain any rich text styling which is usually desirable for UI strings.
  • styles.xml to define style objects.
res/xml/ Arbitrary XML files that are compiled and can be read at run time by calling Resources.getXML().
res/raw/ Arbitrary files to copy directly to the device. They are added uncompiled to the compressed file that your application build produces. To use these resources in your application, call Resources.openRawResource() with the resource ID, which is R.raw.somefilename.

Resource는 apk file로 컴파이 되는데, 안드로이드는 이와 관련된 R이라는 wrapper class를 생성한다. R class에는 source path와 file 명에 따라 이름지어지는 subclass를 포함하고 있다.

Tip: 몇몇 resource는 색상을 정의한다. 안드로이드는 다양한 web-style format으로 씌여진 색상을 지원한다.
       또한 alpha channel value를 설정할 수 있다. 처음 2개의 16진수는 투명을 나타내며, alpha channel의 0은 투명을 나타낸다.

Using Resources
  Compile 시에 안드로이드는 프로그램에서 사용하는 모든 resource에 대해 Resource ID를 가지고 있는 R 이라는 class를 생성한다.
package com.android.samples;
public final class R {
    public static final class string {
        public static final int greeting=0x0204000e;
        public static final int start_button_text=0x02040001;
        public static final int submit_button_text=0x02040008;
        public static final int main_screen_title=0x0204000a;
    };
    public static final class layout {
        public static final int start_screen=0x02070000;
        public static final int new_user_pane=0x02070001;
        public static final int select_user_list=0x02070002;

    };
    public static final class drawable {
        public static final int company_logo=0x02020005;
        public static final int smiling_cat=0x02020006;
        public static final int yellow_fade_background=0x02020007;
        public static final int stretch_button_1=0x02020008;

    };
};

1. Using Resources in Code
  Source code 내에서 resource를 사용하기 위해서는 resource ID와 어떤 종유의 object가 compile되었는지 아는 것이 중요하다.
code 내에서 resource는 아래와 같이 사용한다.
R.resource_type.resource_name
or
android.R.resource_type.resource_name
을 이용하며 그 사용예는 아래와 같다.

// Load a background for the current screen from a drawable resource.
this.getWindow().setBackgroundDrawableResource(R.drawable.my_background_image);

// WRONG Sending a string resource reference into a
// method that expects a string.
this.getWindow().setTitle(R.string.main_title);

// RIGHT Need to get the title from the Resources wrapper.
this.getWindow().setTitle(Resources.getText(R.string.main_title));

// Load a custom layout for the current screen.
setContentView(R.layout.main_screen);

// Set a slide in animation for a ViewFlipper object.
mFlipper.setInAnimation(AnimationUtils.loadAnimation(this,
        R.anim.hyperspace_in));

// Set the text on a TextView object.
TextView msgTextView = (TextView)findViewByID(R.id.msg);
msgTextView.setText(R.string.hello_message);

2. References to Resources 
  XML내의 attribute에 value로 resource를 참조할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<EditText id="text"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:textColor="@android:color/opaque_red"
    android:text="@string/hello_world" />

3. References to Theme Attributes
  Resource value가 현재 Theme의 attribute value로 사용될 수 있는데 이경우는 style resrouce와 XML attributed에서만 참조할 수 있다.
<?xml version="1.0" encoding="utf-8"?>
<EditText id="text"
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent" android:layout_height="fill_parent"
    android:textColor="?android:textDisabledColor"
    android:text="@string/hello_world" />

4. Using System Resources
  System에서 제공되는 Resources를 사용할 수도 있는데, 이러한 Resource는 android.R class에 정의되어 있다.
public class MyActivity extends Activity
{
    public void onStart()
    {
        requestScreenFeatures(FEATURE_BADGE_IMAGE);

        super.onStart();

        setBadgeResource(android.R.drawable.sym_def_app_icon);
    }
}

Alternate Resources (for alternate languages and configurations) 
  UI Language나 device의 hardware configuration에 따라 서로다른 Resource를 적용할 수도 있다.
res/values-en/strings.xml
res/values-fr/strings.xml

Resource에 위와 같이 저장되어 있가고 가정하면, Language가 English인 경우는 values-en/ 을 사용하게 된다.

또한 다양한 구분을 추가할 수 있는데 "-"를 사용하여 추가 가능하다.
res/drawable-en-rUS-large-long-port-mdpi-finger-keysexposed-qwerty-navexposed-dpad-480x320/

폴더 명에는 다음과 같은 qualifier가 추가될 수 있다.
Qualifier Values
MCC and MNC

The mobile country code optionally followed by mobile network code from the SIM in the device. For example mcc310 (U.S. on any carrier); mcc310-mnc004 (U.S., Verizon brand); mcc208-mnc00 (France, Orange brand); mcc234-mnc00 (U.K., BT brand).

If the device uses a radio connection (GSM phone), the MCC will come from the SIM, and the MNC will come from the network to which the device is attached. You might sometimes use the MCC alone, for example to include country-specific legal resources in your application. If your application specifies resources for a MCC/MNC combination, those resources can only be used if both the MCC and the MNC match.

Language and region

The two letter ISO 639-1 language code optionally followed by a two letter ISO 3166-1-alpha-2 region code (preceded by lowercase "r"). For example fr, en-rUS, fr-rFR, es-rES.

The codes are not case-sensitive; the r prefix is used to distinguish the region portion. You cannot specify a region alone, but you can specify a language alone, for example en, fr, es.

Screen dimensions

small, normal, large

Specify that the resource is for a particular class of screen. The meanings of these are:

  • Normal screens are based on the traditional Android HVGA medium density screen. A screen is considered to be normal if it is at least this size (independent of density) and not large. Examples of such screens a WQVGA low density, HVGA medium density, WVGA high density.
  • Small screens are based on the space available on a QVGA low density screen. Considering a portrait HVGA display, this has the same available width but less height -- it is 3:4 vs. HVGA's 2:3 aspect ratio. Examples are QVGA low density and VGA high density.
  • Large screens are based on the space available on a VGA medium density screen. Such a screen has significantly more available space in both width and height than an HVGA display. Examples are VGA and WVGA medium density screens.
Wider/taller screens

long, notlong

Specify that the resource is for a taller/wider than traditional screen. This is based purely on the aspect ration of the screen: QVGA, HVGA, and VGA are notlong; WQVGA, WVGA, FWVGA are long. Note that long may mean either wide or tall, depending on the current orientation.

Screen orientation

port, land, square

Specifies that the resource is for a screen that is tall (port) or wide (land); square is not currently used.

Screen pixel density

ldpi, mdpi, hdpi, nodpi

Specifies the screen density the resource is defined for. The medium density of traditional HVGA screens (mdpi) is defined to be approximately 160dpi; low density (ldpi) is 120, and high density (hdpi) is 240. There is thus a 4:3 scaling factor between each density, so a 9x9 bitmap in ldpi would be 12x12 is mdpi and 16x16 in hdpi. The special nodpi density can be used with bitmap resources to prevent them from being scaled at load time to match the device density.

When Android selects which resource files to use, it handles screen density differently than the other qualifiers. In step 1 of How Android finds the best matching directory (below), screen density is always considered to be a match. In step 4, if the qualifier being considered is screen density, Android will select the best final match at that point, without any need to move on to step 5.

You can also specify explicit densities like 92dpi or 108dpi, but these are not fully supported by the system so should not be used.

Touchscreen type notouch, stylus, finger
Whether the keyboard is available to the user

keysexposed, keyshidden, keyssoft

If your application has specific resources that should only be used with a soft keyboard, use the keyssoft value. If no keyssoft resources are available (only keysexposed and keyshidden) and the device shows a soft keyboard, the system will use keysexposed resources.

Primary text input method nokeys, qwerty, 12key
Whether the navigation keys are available to the user

navexposed, navhidden

If the hardware's navigation keys are currently available to the user, the navexposed resources will be used; if they are not available (such as behind a closed lid), navhidden will be used.

Primary non-touchscreen
navigation method
nonav, dpad, trackball, wheel
Screen dimensions 320x240, 640x480, etc. The larger dimension must be specified first. This configuration is deprecated and should not be used; use instead screen dimension, wider/taller screens, and screen orientation described above.
SDK version The SDK version supported by the device, for example v3. The Android 1.0 SDK is v1, the 1.1 SDK is v2, and the 1.5 SDK is v3.
(Minor version) (You cannot currently specify minor version. It is always set to 0.)

Tip: qualifier는 위 table에 명명된 순서대로 정의되어야 한다.


Posted by 피의복수

안드로이드 Application은 resources를 위한 directory(res/)와 assets을 위한 directory(assets/)을 가지고 있다.
Resource란 Application에 포함되거나 참조되는 external elements를 말하며 image, audio, string 및 theme 등이 있다.
Asset은 자주 사용되지는 않지만, raw bytes를 읽어들일 필요가 있을 때 asset으로 data를 저장할 수 있다.

Resource와 Asset은 표면적인 차이는 많지 않다. 일반적으로 개발자들은 external content를 저장하기 위해 asset보다는 resource를 더 자주 사용하게 된다.
둘 사이의 차이점은 사용방법에 있다. Resource는 R class를 통해 쉽게 접근하여 사용할 수 있는 반면 Asset은 bytes stream을 읽기 위해 AssetManager를 사용해야 한다. 따라서 Resource를 사용하는 것이 파일과 데이터를 접근하기에 훨씬 용이하다.






Posted by 피의복수

Activity가 focus를 받으면 Layout을 그리라는 요청이된다.
안드로이드 Framework은 drawing을 위한 procedure를 다룰 것이고 Activity는 Layout hierarchy의 root node를 제공해야 한다.
Drawing은 Layout의 root node에서 시작되며, Layout tree를 측정하고 그리게 된다.
Drawing은 Layout tree르 순차적으로 점검하고 유효하지 않은 위치를 교차하는 각각의 View를 redering함으로써 조절된다.
차례로, 각 View Group은 각각의 child view에 draw() method로 그릴 것을 요청하며, 각 View는 자신을 그린다.
layout tree는 순차적으로 진행되며, 따라서 parents는 child view 전에 그려지며, tree에 정의된 순서대로 child가 그려지게 된다.

Layout을 그리는 방법은 다음과 같은 두가지의 pass process로 되어 있다.
A measure pass
  measure pass는 measure() method에서 수행되며, View tree의 top-down 으로 전개된다. 각 View는 반복하는 동안 dimension 특성을 tree에 전달한다. measure pass의 마지막에 모든 View는 자신의 measurements를 저장한다.

A layout pass
  Layout pass는 layout() method에서 발생하며, measure pass와 마찬가지로 top-down 방식이다. 
layout pass가 수행되는 동안 각 parents는 measure pass가 계산한 사이즈를 이용하여 자신의 모든 child view를 positioning 한다.

 

 
Posted by 피의복수
<< PREV : [1] : [2] : [3] : [4] : [5] : [6] : [7] : [8] : NEXT >>

BLOG main image
일에 필요한 자료 by 피의복수

카테고리

분류 전체보기 (40)
프로그램이야기 (38)
끄적끄적 (1)
취미 (0)
서비스이야기 (1)
빅데이터 (0)

최근에 올라온 글