Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. private fun createTextView(text: String, index: Int, wordsDone: () -> Unit): TextView {
  2. val lparams = ViewGroup.LayoutParams(
  3. ViewGroup.LayoutParams.WRAP_CONTENT,
  4. ViewGroup.LayoutParams.WRAP_CONTENT
  5. ) // Width , height
  6. // XXX Write me
  7. val textView = TextView(context)
  8. textView.layoutParams = lparams
  9. if (index < 6)
  10. {
  11. textView.id = ids.getResourceId(index, 0)
  12. }
  13. textView.setText(text)
  14. textView.setTextSize(18f)
  15. textView.setPadding(8, 8, 8, 8)
  16. textView.setBackgroundColor(neutralBgColor)
  17. val textViewHeight = findTVHeight(textView).toFloat()
  18. val numberOfRows = (frame.measuredHeight / textViewHeight).toInt() - 1
  19. var randomInt = (0..numberOfRows).random()
  20. val textViewMaxX = (frameMaxX-8-findTVWidth(textView)).toInt()
  21. while (randomIntList.contains(randomInt))
  22. randomInt = (0..numberOfRows).random()
  23. randomIntList.add(randomInt)
  24. val yCoordinate = randomInt * textViewHeight
  25. textView.y = yCoordinate
  26. textView.x = ((8..textViewMaxX).random()).toFloat()
  27. textViewList.add(textView)
  28. textView.setOnClickListener {
  29. if (click == index)
  30. {
  31. textView.visibility = View.INVISIBLE
  32. if (click == maxClick)
  33. wordsDone()
  34. click++
  35. }
  36. else
  37. outOfOrderPick(textView)
  38. }
  39. frame.addView(textView)
  40. return textView
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement