Question

the default position of the radio group is the top left side of the screen, and I want it to be at the top right. i tried to use padding like so: radioGroup.setPadding(layout.getRight() - radioGroup.getWidth(), layout.getTop(), layout.getRight(), layout.getTop() + radioGroup.getHeight()) but it won't change the radio gruop's position

Was it helpful?

Solution

If your RadioGroup parent is a RelativeLayout, just add the tags android:layout_alignParentRight=true and android:layout_alignParentTop=true.

Via code, check http://developer.android.com/reference/android/widget/RelativeLayout.LayoutParams.html . It's a matter of using addRule() for specifying both constraints in your RelativeLayout.LayoutParams object, and then applying it to the RadioGroup.

If your RadioGroup parent is a LinearLayout, try setting the LinearLayout android:gravity="top|right".

Similarly, via code, you can use setGravity(Gravity.TOP | Gravity.RIGHT) in your LinearLayout object.

Hope that helps!

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top