목록Kotlin (30)
Foggy day

Kotlin don't have static. But it have companion object. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) Person.create("companion object text") } data class Person(val name: String, val registered: Instant = Instant.now()) { companion object { fun cre..

If you use destructing, you can access to object properties much easier. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val persons = listOf(Person("jinhan"), Person("jinhan2"), Person("jinhan3")) show(persons) } data class Person(val name: String, ..

If you declare a value of variable in constructor, you don't need add parameter when you create class. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val person = Person("jinhan") println("person name : ${person.name}, registered : ${person.register..
Add open in front of class to extend class in kotlin. class KotlinPlayGroundActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) val people = People("jinhan", 30) println("name : ${people.name}, age : ${people.age}") } class People(name: String, age: Int) : Person(name, age) {..
1. class Person constructor(name: String) { val name: String init { this.name = name } } 2. class Person constructor(name: String) { val name: String = name } 3. class Person constructor(val name: String) { } 4. class Person(val name: String) { }

It is about initialization of lazy. class KotlinPlayGroundActivity : AppCompatActivity() { val name: String by lazy { getName() } val name2: String by lazy(::getName) override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity_kotlin_play_ground) println("hello") println("name 1 : $name") println("name 2 : $name2") } @JvmName("getName1..

This article is an example of LayoutParams. Sometimes, you want to change propertis of view like margin or width in code. It is for that. what we need to know to use LayoutParams is ViewGroup. There are FrameLayout, Linearlayout, ConstraintLayout and RelativeLayout as ViewGroup. we can include child view like TextView, Button, and EditText. To use LayoutParams, we have to access ViewGroup. If Vi..

아래 링크의 글을 번역한 글입니다. vladsonkin.com/android-custom-view-extending-the-views/ Android Custom View: Extending The Views - vladsonkin.com Android has lots of different Views, and you can build almost any app with them. However, sometimes they will not fulfill your requirements, mostly if your design is filled with unusual elements and animations. To handle this case, Android gives us the pos vladson..
It is the sample of custom circle progressbar that use customview and valueanimation. If you want to use circle percent Progress, I recommend this sample. Additional explanations have been omitted. I left a little explanation in the code. But, It is not English. If you have any questions, please leave a comment. Video preview 1. CircleProgress @SuppressLint("ResourceAsColor") class CircleProgres..
Normal viewpager does not have the wrapContent attribute applied. However, someTimes we need to set height of the ViewPager to match the contents. So I created a CustomViewPager class that extends ViewPager and The CustomViewPager allows you to flexibly set height of ChildViews. To understand this post, you must have a basic understanding of ViewPager. Video preview 1. CustomViewPager First of a..