2017-11-20 4 views
1

Kotlin의 ConstraintLayout에 함수를 구현하는 방법을 알아야합니다.보기에 Kotlin 함수를 구현하는 방법

fun applyCustomPropeties(){ 
    //some stuff 
} 

val rootLayout = findViewById<ConstraintLayout>(R.id.rootLayout) 

rootLayout.applyCustomPropeties() 

감사 :

나는 이런 식으로 뭔가를해야합니다. 그 확장 "정적"해결

fun ConstraintLayout.applyCustomProperties() { 
    //some stuff 
    //you can use "this" keyword here 
} 

, 당신이 그 코드를 삽입 그래서 상관없이 :

답변

2

당신은 확장 기능을 추가 할 수 있습니다. 이제 원하는 것을 할 수 있습니다.

val rootLayout = findViewById<ConstraintLayout>(R.id.rootLayout) 
rootLayout.applyCustomPropeties() 
+0

니스, 감사합니다. – Freiver

관련 문제