I need to know the size of a Button (or any other view). But none of the procedures in lifecycle (onCreate, onStart, OnResume) seem to know it, as the Button seems not yet to be initialized!
...
import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : AppCompatActivity() {
private var servOffset: Int=0 // Value depends on Layout/Orientation and Device
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
btPunkte.setOnClickListener { doPunkt(true) }
servOffset = btPR1.width/2 // 'btPR1' is a Button in 'Layout activity_main.*'
//ToDo: Doesn't work! = remains 0
}
override fun onResume() {
super.onResume()
// ToDo: unsolved! When do I get the size??
// onStart (or onResume) are invoked correctly, but don't know the value!
// ?? Button doesn't yet exist in Livecycle?!
servOffset = btPR1.width/2 // //ToDo: Still doesn't work!
anzeigeAktualisieren()
}
private fun anzeigeAktualisieren() {
// If ... move Button
btPR1.x += servOffset //ToDo: unsolved offset remains 0 ?!
}
private fun doPunkt(links:Boolean) {
anzeigeAktualisieren()
...
}
...
}
I did find "When are views drawn", and several other threads, but they didn't help me solve my problem.