0
 val param =  LinearLayout.LayoutParams(WRAP_CONTENT,WRAP_CONTENT)
        param.rightMargin = 100

        val rb = RadioButton(this)
        rb.text = "1"
        rb.setTextColor(Color.parseColor("#ffffff"))
        rb.layoutParams = param

        rgroup.addView(rb)

        val rb2 = RadioButton(this)
        rb2.text = "2"
        rb2.setTextColor(Color.parseColor("#ffffff"))
        rb2.layoutParams = param
        rgroup.addView(rb2)

first set layoutparams for rb and then add it to radiogroup , the right margin do no work when run in android M , but works over M ,its cause by diff andoird version ? the same code , the diff result

jaygee
  • 25
  • 3

1 Answers1

0

Use RadioGroup.LayoutParams instead of LinearLayout.LayoutParams

Saurabh Thorat
  • 18,131
  • 5
  • 53
  • 70
  • yeah , it works , emm , but what im wonder is why ```LinearLayout.LayoutParams ``` has no effect in M , is version difference ? – jaygee Nov 23 '19 at 02:24
  • You must use the parent layout’s LayoutParams when setting params. Can’t say why it wasn’t working for you in M. Also please mark the answer as accepted if it has solved your problem. – Saurabh Thorat Nov 23 '19 at 09:04