I am creating FrameLayout dynamically using the following code
mylayout.java
FrameLayout layout = new FrameLayout(this);
FrameLayout.LayoutParams layoutp
Add
layout.setGravity(Gravity.CENTER_HORIZONTAL|Gravity.CENTER_VERTICAL);
or
layout.setGravity(Gravity.CENTER);
You forgot to set the gravity of the layout.
Android Developer - Frame Layout Documentation reads:
Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other. You can, however, add multiple children to a FrameLayout and control their position within the FrameLayout by assigning gravity to each child, using the android:layout_gravity
attribute.
In your case, you may use layout.setForegroundGravity(int)
for the same.