kotllin自定义view_Android kotlin+anko自定义view进阶篇(一)

开篇

我最近在学习Kotlin+Anko组合开发Android App。如何用Kotlin+Anko自定义控件,网上的资料不但少,而且还很凌乱。经过一段时间的摸索我大概掌握了这娘们的脾气了。今天就教童鞋们如何用Kotlin+Anko自定义控件。

效果图

实现

1、kotlin自定义view(横向排列三个控件:ImageView、TextView、ImageView):JSCItemLayout.kt

class JSCItemLayout : FrameLayout, IBaseView {

//私有成员

private lateinit var iconView: ImageView

private lateinit var labelView: TextView

private lateinit var arrowView: ImageView

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(context)要在retrieveAttributes(attrs)前调用

//因为属性赋值,会直接赋值到控件上去。如:

//调用label = ""时


本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!

相关文章

立即
投稿

微信公众账号

微信扫一扫加关注

返回
顶部