Advertisement
Guest User

Untitled

a guest
Jun 24th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. class SampleActivity : BaseActivity() {
  2.  
  3. override fun onCreate(savedInstanceState: Bundle?) {
  4. super.onCreate(savedInstanceState)
  5. SampleActivityUI().setContentView(this)
  6.  
  7. /*** kotlinのみでの実装 ***/
  8. findViewById<RelativeLayout>(R.id.container).apply {
  9. val textView = TextView(this@SampleActivity)
  10. textView.textSize = 18F
  11. val textViewParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT)
  12. textViewParams.addRule(RelativeLayout.CENTER_HORIZONTAL)
  13. textViewParams.setMargins(0, 20, 0, 0)
  14. addView(textView, textViewParams)
  15.  
  16. val seekBar = SeekBar(this@SampleActivity).apply {
  17. progress = 5
  18. max = 10
  19.  
  20. setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
  21. override fun onProgressChanged(seekBar: SeekBar?, progress: Int, fromUser: Boolean) {
  22. textView.text = progress.toString()
  23. }
  24.  
  25. override fun onStartTrackingTouch(seekBar: SeekBar?) {
  26. }
  27.  
  28. override fun onStopTrackingTouch(seekBar: SeekBar?) {
  29. }
  30. })
  31. }
  32. val seekBarParams = RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT)
  33. seekBarParams.addRule(RelativeLayout.CENTER_IN_PARENT)
  34. addView(seekBar, seekBarParams)
  35. }
  36.  
  37. /*** kotlin + Ankoでの実装 ***/
  38. // find<RelativeLayout>(R.id.container).apply {
  39. // val textView = textView().apply {
  40. // textSize = 18F
  41. //
  42. // layoutParams = RelativeLayout.LayoutParams(wrapContent, wrapContent).apply {
  43. // addRule(RelativeLayout.CENTER_HORIZONTAL)
  44. // verticalMargin = dip(10)
  45. // }
  46. // }
  47. //
  48. // seekBar().apply {
  49. // progress = 5
  50. // max = 10
  51. //
  52. // onSeekBarChangeListener {
  53. // onProgressChanged { seekBar, i, b ->
  54. // textView.text = i.toString()
  55. // }
  56. // }
  57. //
  58. // layoutParams = RelativeLayout.LayoutParams(matchParent, wrapContent).apply {
  59. // addRule(RelativeLayout.CENTER_IN_PARENT)
  60. // }
  61. // }
  62. // }
  63. }
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement