Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private fun createTextView(text: String, index: Int, wordsDone: () -> Unit): TextView {
- val lparams = ViewGroup.LayoutParams(
- ViewGroup.LayoutParams.WRAP_CONTENT,
- ViewGroup.LayoutParams.WRAP_CONTENT
- ) // Width , height
- // XXX Write me
- val textView = TextView(context)
- textView.layoutParams = lparams
- if (index < 6)
- {
- textView.id = ids.getResourceId(index, 0)
- }
- textView.setText(text)
- textView.setTextSize(18f)
- textView.setPadding(8, 8, 8, 8)
- textView.setBackgroundColor(neutralBgColor)
- val textViewHeight = findTVHeight(textView).toFloat()
- val numberOfRows = (frame.measuredHeight / textViewHeight).toInt() - 1
- var randomInt = (0..numberOfRows).random()
- val textViewMaxX = (frameMaxX-8-findTVWidth(textView)).toInt()
- while (randomIntList.contains(randomInt))
- randomInt = (0..numberOfRows).random()
- randomIntList.add(randomInt)
- val yCoordinate = randomInt * textViewHeight
- textView.y = yCoordinate
- textView.x = ((8..textViewMaxX).random()).toFloat()
- textViewList.add(textView)
- textView.setOnClickListener {
- if (click == index)
- {
- textView.visibility = View.INVISIBLE
- if (click == maxClick)
- wordsDone()
- click++
- }
- else
- outOfOrderPick(textView)
- }
- frame.addView(textView)
- return textView
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement