当前位置:网站首页>Kotlin of Android cultivation manual - several ways to write a custom view

Kotlin of Android cultivation manual - several ways to write a custom view

2022-06-25 17:43:00 sesame seeds

Share previous articles

This article is about 2.6 Thousand characters , Novice reading needs 4 minute , Review needs 1 minute Collect at any time, no longer get lost

About author

as everyone knows , Life is a long process , constantly overcome difficulties , Constantly reflect on the process of progress . In this process, there will be a lot of questions and thoughts about life , So I decided to put my thinking , Share all your experiences and stories , To find resonance !!!
Focus on Android/Unity And various game development skills , as well as Share various resources ( Website 、 Tools 、 material 、 Source code 、 Games etc. )
If you need anything, welcome me , Communication groups make learning No longer alone .

 Insert picture description here

Premise

This is what Xiao Kong insisted on writing Android Novice series , Welcome to taste .

bosses (√)

Novice (√√√)

Practice process

Use Kotlin Not used to it , Take notes .
There are three ways

Mode one

recommend , Note that the first two construction parameters are this, instead of super

class WaveViewKotlin: View{
    
    constructor(context: Context?) :this(context,null)
    constructor(context: Context?, attrs: AttributeSet?) :this(context,attrs,0)
    constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr)
    init {
    
        // Initialization method 
    }
    override fun onDraw(canvas: Canvas) {
    
      
    }
}

perhaps

class WaveViewKotlin: View{
    
    constructor(context: Context?, attrs: AttributeSet?) :super(context,attrs)
    init {
    
        // Initialization method 
    }
    override fun onDraw(canvas: Canvas) {
    
      
    }
}

Mode two

The other one parameter and three parameters are infeasible

class WaveViewKotlin(context: Context?, attrs: AttributeSet?) : View(context, attrs) {
    
    init {
    
        // Initialization method 
    }
    override fun onDraw(canvas: Canvas) {
    
      
    }
}

Mode three

The premise is that the project's build In the configuration kotlin Plug in for .

class WaveViewKotlin @JvmOverloads constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0) : View(context, attrs, defStyleAttr){
    
    init {
    
        // Initialization method 
    }
    override fun onDraw(canvas: Canvas) {
    
      
    }
}

other

author : Xiaokong and Xiaozhi Xiaokong
Reprint note - Be sure to indicate the source :https://zhima.blog.csdn.net/
This Taoist friend, please Step back ️, I watch you Extraordinary bearing , There is a king's domineering spirit in his speech , There will be a great achievement in the future !!! There is give the thumbs-up Collection Today I tell you , Have you ordered it , Your success in the future ️, I don't take a penny , If it doesn't work ️, Or come back to me .

reminder Click the card below to get more unexpected resources .
 Mr. Kong Ming

原网站

版权声明
本文为[sesame seeds]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251539404703.html