티스토리 뷰

반응형

Stack Overflow에 자주 검색, 등록되는 문제들과 제가 개발 중 찾아 본 문제들 중에서 나중에도 찾아 볼 것 같은 문제들을 정리하고 있습니다.

Stack Overflow에서 가장 먼저 확인하게 되는 가장 높은 점수를 받은 Solution과 현 시점에 도움이 될 수 있는 가장 최근에 업데이트(최소 점수 확보)된 Solution을 각각 정리하였습니다.

 

아래 word cloud를 통해 이번 포스팅의 주요 키워드를 미리 확인하세요.

What does it mean to inflate a view from an xml file?

XML 파일에서 뷰를 인플레이트(inflate)한다는 것은 무엇을 의미할까요?

 문제 내용 

I am new to android development and keep coming across references to Inflating views from a layout xml file. I googled and searched the development guide but still wasn't able to pick up a sense for what it means. If someone could provide a very simple example, it'd be much appreciated.

저는 안드로이드 개발에 처음 입문하여, 최근에 레이아웃 XML 파일로부터 뷰(View)를 인플레이트하는 방법에 대해 많이 찾아보고 있습니다. 구글링과 안드로이드 개발 가이드를 찾아보았지만, 그 의미를 제대로 이해하지 못하였습니다. 간단한 예시를 통해 설명해주시면 감사하겠습니다.

 

 

 

 높은 점수를 받은 Solution 

When you write an XML layout, it will be inflated by the Android OS which basically means that it will be rendered by creating view object in memory. Let's call that implicit inflation (the OS will inflate the view for you). For instance:

XML 레이아웃을 작성하면 안드로이드 운영 체제가 해당 레이아웃을 인플레이트(inflate)하여 메모리에 뷰(View) 객체를 생성하게 됩니다. 이것을 암묵적 인플레이션(implicit inflation)이라고 합니다. 예를 들면 다음과 같습니다.
class Name extends Activity{
    public void onCreate(){
         // the OS will inflate the your_layout.xml
         // file and use it for this activity
         setContentView(R.layout.your_layout);
    }
}

 

You can also inflate views explicitly by using the LayoutInflater. In that case you have to:

또한 LayoutInflater를 사용하여 명시적으로 뷰(View)를 인플레이트할 수도 있습니다. 이 경우, 다음과 같은 단계를 거쳐야 합니다.

 

  1. Get an instance of the LayoutInflater
  2. Specify the XML to inflate
  3. Use the returned View
  4. Set the content view with returned view (above)
1. LayoutInflater의 인스턴스를 얻기
2. 인플레이트할 XML 파일을 지정하기
3. 반환된 뷰(View) 사용하기
4. 반환된 뷰(View)를 컨텐트 뷰(content view)로 설정하기

 

For instance:

예를 들면 다음과 같습니다.
LayoutInflater inflater = LayoutInflater.from(YourActivity.this); // 1
View theInflatedView = inflater.inflate(R.layout.your_layout, null); // 2 and 3
setContentView(theInflatedView) // 4

 

 

 가장 최근 달린 Solution 

A layman definition for inflation might be to convert the XML code to Java code. Just a way to understand, e.g., if we have a tag in XML, OS has to create a corresponding Java object in memory, so inflatter reads the XMLtags, and creates the corresponding objects in Java.

인플레이션(inflation)을 무식하게 설명하자면, XML 코드를 자바 코드로 변환하는 것이라고 할 수 있습니다. 즉, XML 태그에 해당하는 뷰(View) 객체를 메모리에 생성해야 하므로 인플레이터(infalter)는 XML 태그를 읽고 자바 객체로 변환하는 작업을 수행합니다.

 

 

 

출처 : https://stackoverflow.com/questions/4576330/what-does-it-mean-to-inflate-a-view-from-an-xml-file

반응형
댓글
공지사항
최근에 올라온 글