-1

I try to add view to my custom view group but all my attempts are unsuccessful My custom view group

class CircleView : ViewGroup, View.OnTouchListener {

private var controller: SpeedControllerImp? = null

constructor(context: Context) : super(context) {
    init()
}

constructor(context: Context, attrs: AttributeSet?) : super(context, attrs) {
    var mTextView = TextView(this.context)
    mTextView?.setTextColor(Color.WHITE)
    mTextView?.textSize = 150F
    val params = LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)
    mTextView?.layoutParams = params
    mTextView?.text = "asdasadasdasdasdasdasdasdasdasdasdasdasdas"

    this.addView(mTextView)
    init()
}

/* override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {

    val count = childCount
    for (i in 0..count - 1) {
        var childView = getChildAt(i)
        childView.measure(widthMeasureSpec, heightMeasureSpec)
    }
    super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}

*/ override fun onLayout(changed: Boolean, l: Int, t: Int, r: Int, b: Int) {

}

override fun onDraw(canvas: Canvas) {
    super.onDraw(canvas)
    controller?.onDraw(canvas)
    invalidate()
}

override fun onSizeChanged(w: Int, h: Int, oldw: Int, oldh: Int) {
    controller?.onSizeChanged(w, h)
    super.onSizeChanged(w, h, oldw, oldh)
}

override fun onTouch(v: View, event: MotionEvent): Boolean {
    controller?.onTouchEvent(event)
    return true
}

private fun init() {
    setWillNotDraw(false)
    setOnTouchListener(this)
    controller = SpeedControllerImp()
}

} fun onMeasure don't help me( Where is my error?

Eugene Surkov
  • 255
  • 1
  • 3
  • 9
  • 1
    your `onLayout()` is empty so your children are not laid out, whats the output of `adb shell dumpsys activity top`? – pskink May 29 '17 at 16:02

1 Answers1

0

So, just extends FrameLayout and all will be good class CircleView : FrameLayout

Eugene Surkov
  • 255
  • 1
  • 3
  • 9