Android ShapeableImageView rotation in Kotlin code
Kotlin
import android.content.Context
import android.util.AttributeSet
import android.util.Log
import com.google.android.material.imageview.ShapeableImageView
class MyImageView(ctx: Context, attrs: AttributeSet?, defStyleAttr: Int) :
ShapeableImageView(ctx, attrs, defStyleAttr) {
private val TAG = "fly/${this::class.simpleName}"
//init代码块相当于Java的static静态代码块。
init {
Log.d(TAG, "init")
rotation = -30F //逆向旋转30°
Log.d(TAG, "旋转 $rotation")
}
constructor(context: Context) : this(context, null, 0) {
Log.d(TAG, "constructor-1")
}
constructor(context: Context, attrs: AttributeSet) : this(context, attrs, 0) {
Log.d(TAG, "constructor-2")
}
}