Given the layout of main.xml below, is it possible to change the "layout_gravity" for FrameLayout at run time with immediate result?
My main layout is LinearLayout and a centered FrameLayout child with two children, SurfaceView and ImageView (located at the bottom of the frame).
I have a menu that allows the user to move the frame structure, which should be done by changing the layout_gravity to "top", "bottom" or "center".
For this, I use this code to change the gravity at runtime:
int mGravity = Gravity.TOP
FrameLayout mFrameLayout = (FrameLayout)findViewById(R.id.my_framelayout);
((LinearLayout.LayoutParams) mFrameLayout.getLayoutParams()).gravity = mGravity;
However, this does not work immediately. I just started working after the user clicks on another menu item that displays them on the Android Market. When a user returns from the market and returns to my application, only then a new layout is drawn in accordance with what the user previously selected.
Am I missing something simple? How can I force a redraw immediately after a user selects a position? What should I make invalid?
main.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/ll_main"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<FrameLayout
android:id="@+id/my_framelayout"
android:layout_width="fill_parent"
android:layout_height="@dimen/surfaceview_default_h"
android:layout_gravity="center">
<SurfaceView
android:id="@+id/my_surfaceview"
android:layout_width="@dimen/surfaceview_default_w"
android:layout_height="@dimen/surfaceview_default_h">
</SurfaceView>
<ImageView
android:id="@+id/my_imageview"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:src="@drawable/someimage"
android:layout_gravity="bottom">
</ImageView>
</FrameLayout>
</LinearLayout>
menu.xml:
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/mnu_position"
android:title="@string/position">
<menu>
<group
android:id="@+id/grp_position"
android:menuCategory="container"
android:checkableBehavior="single">
<item
android:id="@+id/mnu_position_top"
android:title="@string/top">
</item>
<item
android:id="@+id/mnu_position_center"
android:title="@string/center"
android:checked="true">
</item>
<item
android:id="@+id/mnu_position_bottom"
android:title="@string/bottom">
</item>
</group>
</menu>
</item>
<item
android:id="@+id/mnu_android_market"
android:title="@string/market">
</item>
</menu>
Jason source
share