티스토리 뷰

반응형

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

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

 

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

What's "tools:context" in Android layout files?

Android 레이아웃 파일에서 "toos:context"란 무엇입니까?

 문제 내용 

Starting with a recent new version of ADT, I've noticed this new attribute on the layout XML files, for example:

최근 새로운 버전의 ADT를 시작으로 레이아웃 XML 파일에서 다음과 같은 새로운 속성을 발견했습니다.

 

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    tools:context=".MainActivity" />

What is "tools:context" used for?

"tools:context"는 무엇에 사용됩니까?

 

How does it even know the exact path to the activity that is written there? Does it look at the package of the app, inside the manifest?

어떻게 거기에 적혀있는 활동의 정확한 경로를 알 수 있을까요? 매니페스트 안에 있는 앱 패키지를 보는 건가요?

 

Is it limited to classes that extend Context or only activities? Is it usable for ListView items etc.?

컨텍스트를 확장하는 클래스로 제한됩니까, 아니면 액티비티만 제한합니까? ListView 항목 등에 사용할 수 있습니까?

 

 

 

 높은 점수를 받은 Solution 

This is the activity the tools UI editor uses to render your layout preview. It is documented here:

이것은 UI 편집기가 레이아웃 미리보기를 렌더링하는 데 사용하는 액티비티입니다. 여기에 설명되어 있습니다.

 

This attribute declares which activity this layout is associated with by default. This enables features in the editor or layout preview that require knowledge of the activity, such as what the layout theme should be in the preview and where to insert onClick handlers when you make those from a quickfix

이 속성은 이 레이아웃이 기본적으로 연결된 활동을 선언합니다. 이렇게 하면 미리보기에서 레이아웃 테마가 무엇인지, 빠른 수정을 통해 만들 때 클릭 핸들러에 삽입할 위치와 같은 작업에 대한 지식이 필요한 편집기 또는 레이아웃 미리보기의 기능을 사용할 수 있습니다.

 

 

 

 가장 최근 달린 Solution 

This is best solution : https://developer.android.com/studio/write/tool-attributes

이것이 최선의 해결책입니다. https://developer.android.com/studio/write/tool-attributes

 

This is design attributes we can set activty context in xml like

설계 특성입니다. 액티비티 컨텍스트를 xml로 설정할 수 있습니다.

 

tools:context=".activity.ActivityName"

Adapter:

어댑터:

 

tools:context="com.PackegaName.AdapterName"

enter image description here

You can navigate to java class when clicking on the marked icon and tools have more features like

표시된 아이콘을 클릭하면 java 클래스로 이동할 수 있습니다. 그리고 도구는 다음과 같은 더 많은 기능을 가지고 있다.

 

tools:text=""
tools:visibility:""
tools:listItems=""//for recycler view 

etx

 

 

 

출처 : https://stackoverflow.com/questions/11078487/whats-toolscontext-in-android-layout-files

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