开发者

Android Honeycomb: layout problem - hide/show FrameLayouts

in my Activity, I have a layout containing 3 FrameLayouts, one at the top, one at the left and one at the "center".

Now, I sometimes only want to display one or two of them. Atm I am doing it this way:

FrameLayout frame = (FrameLayout) findViewById(R.id.framelayout_menu_left);
frame.setVisibility(...);

frame = (FrameLayout) findViewById(R.id.framelayout_content);
frame.setVisibility(...);

frame = (FrameLayout) findViewById(R.id.framelayout_menu_top);
frame.setVisibility(...);

However this can get really ugly results, e.g. when I switch the "content" Fragment and hide the top and/or left FrameLayout. It all starts flickering as the "content" Fragment jumps to the top and/or left and only afterwards is replaced.

Also, I can obviously not navigate back to another setup, so is there any other way to do this?

Kind regards, jellyfish

Edit:

Maybe a little drawing makes my question clearer...

Android Honeycomb: layout problem - hide/show FrameLayouts

A shows a Layout of 3 FrameLayouts containing 3 different Fragments. Each color represents one distinct Fragment.

Now what I want to do is to switch from A to D. I am doing this by replacing开发者_StackOverflow社区 the blue Fragment with the yellow Fragment via a FragmentTransaction.

However, this still keeps the other Frames visible, so I hide them via the code above.

Now, Frame.setVisibility() is called way before commit(), so in B and C the blue Fragment "jumps" to the left and the top and only afterwards (in D) is replaced with the yellow Fragment. This produces a nasty flickering.

As a workaround, I now hide all three FrameLayouts before the transaction and re-show the ones I need once the transaction has finished. But there still is the problem that I can't go back via the back button as this isn't a real transaction.


I would have two suggestions. Firstly, if you both add a fragment transition effect and do the visibility changes after the transaction, that would probably substantially reduce much of your flicker effect

ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);

Secondly, I've simply given up on having the system manage the fragment stack for me -- it seems that this only works well with simple transactions. Override onBackPressed and do your own logic there.

--randy

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜