Android的蜂窝:布局问题 - 隐藏/显示FrameLayouts [英] Android Honeycomb: layout problem - hide/show FrameLayouts

查看:377
本文介绍了Android的蜂窝:布局问题 - 隐藏/显示FrameLayouts的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的活动,我有一个包含一个布局3 的FrameLayout S,一个在顶部,一个在在中心左之一。

现在,我有时只是想显示一个或两个。 ATM我做这种方式:

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

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

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

不过,这也会带来难看的结果,例如当我切换的内容片段和隐藏的顶部和/或左的FrameLayout 。这一切都开始闪烁的内容片段跳转到顶部和/或左,事后才更换。

另外,我显然不能导航回到另一个设置,所以是有任何其他方式做到这一点?

亲切的问候, 水母

编辑:

也许一个小客厅,使我的问题更清晰...

A 的显示3 FrameLayouts含有3种不同的片段布局。再presents每种颜色一个不同片段。

现在我想要做的是从的 A 的切换的ð的。 我对通过与黄色片段取代蓝色碎片这样一个 FragmentTransaction

不过,这仍保持其他帧可见的,所以我通过code以上隐藏起来。

现在, Frame.setVisibility()被称为方式前提交(),所以在 B C 的蓝色片段跳跃的左侧和顶部和事后才(在ð的)被替换为黄色片段。这将产生一个讨厌的闪烁。<​​/ P>

作为一种解决办法,我现在隐藏在交易前三个FrameLayouts并重新显示出那些我需要的,一旦交易完成。但是,仍然是无法通过后退按钮返回,因为这不是一个真正的交易问题。

解决方案

我有两个建议。首先,如果你俩加一个片段过渡效果,做了交易后的可见性的变化,这可能会大大减少你很多闪烁效果

  ft.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_FADE);
 

其次,我干脆放弃了对具有系统管理片段堆栈我 - 似乎这只是简单的交易运作良好。覆盖onBack pressed,做你自己的逻辑在那里。

- 兰迪

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...

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 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

这篇关于Android的蜂窝:布局问题 - 隐藏/显示FrameLayouts的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆