locked
Center a programmatically created radio button in its linear layout vertical parent Android RRS feed

  • Question

  • User299676 posted

    I am creating a linear layout programmatically with orientation = vertical. In that linear layout I am also creating 2 or 3 objects programmatically:

    1-Image view 2-Text View (I create this object if it is needed) 3-Radio button

    By problem is how I can center the radio button in its parent ?

    Thursday, May 11, 2017 11:02 AM

Answers

  • User299676 posted

    I fixed it by creating LayoutParams for every view and add it with its view to the parent linear layout.

    LinearLayout.LayoutParams center = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Gravity = GravityFlags.Center };

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 21, 2017 9:40 AM

All replies

  • User322801 posted

    have u tried setting the gravity of the radio button to center?

    Thursday, May 11, 2017 1:58 PM
  • User299676 posted

    @bjorn130 said: have u tried setting the gravity of the radio button to center?

    Yes I have tried :( You can check this thread if you want http://stackoverflow.com/questions/43913514/center-a-programmatically-created-radio-button-in-its-linear-layout-vertical-par

    Friday, May 12, 2017 6:02 AM
  • User299676 posted

    I fixed it by creating LayoutParams for every view and add it with its view to the parent linear layout.

    LinearLayout.LayoutParams center = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WrapContent, ViewGroup.LayoutParams.WrapContent) { Gravity = GravityFlags.Center };

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Wednesday, June 21, 2017 9:40 AM