I have a FrameLayout in which I have 2 controls: - a custom view which draws a image and some text on it - a textview with a text
I want to center both in the FrameLayo
We can align a view in center of the FrameLayout
by setting the layout_gravity
of the child view.
In XML:
android:layout_gravity="center"
In Java code:
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.CENTER;
Note: use FrameLayout.LayoutParams
not the others existing LayoutParams