我试图用片段重现Honeycomb GMail UI并且不能。这就是我想要的东西
初始状态:
+--------+---------------+
| | |
|Accounts| Folders |
| | |
+--------+---------------+
选择文件夹后:
+--------+---------------+
| | |
|Folders | Items |
| | |
+--------+---------------+
其中帐户,文件夹和项目是片段。 (显然后退按钮应该进入初始状态)
我尝试了以下布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:id="@+id/root">
<FrameLayout
android:id="@+id/left_pane" android:layout_weight="1"
android:layout_width="0px" android:layout_height="match_parent" />
<FrameLayout
android:id="@+id/right_pane" android:layout_weight="1.6"
android:layout_width="0px" android:layout_height="match_parent" />
</LinearLayout>
不幸的是,这不起作用,因为我无法将我的文件夹片段从右窗格移动到左窗格(片段只能添加一次)。我可以创建新的文件夹,但这非常浪费资源,需要仔细的状态管理(特别是当按下后退按钮时)并且看起来不像我想要的样子。
我尝试使用3个FrameLayouts(左,中,右,权重1,1.6,2.56),但是当片段未显示时,我无法使FrameLayout崩溃。任何帮助都非常感谢
答案 0 :(得分:6)
使用Nicholas的帖子建议的三帧布局在我的应用中很棒。为了保持比率正确,您可能需要动态更改布局权重(尽管我认为可能不会这样做)。我使用这个辅助方法来处理所有这些逻辑。请注意,它需要几个助手;一般来说,应该清楚那些需要从他们的名字做什么,所以我没有在这里发布。但有一件事是,我有一个包含所有框架的成员数组,因此这种方法可以自动隐藏任何不需要的东西。
final private void showFrames(View leftFrame, View rightFrame) {
// Hide frames that should be gone
for (View frame : mContentFrames) {
if (frame != leftFrame && frame != rightFrame) {
frame.setVisibility(View.GONE);
Fragment frag = getFragmentManager().findFragmentById(frame.getId());
if (frag != null) {
getFragmentTransaction().remove(frag);
}
}
}
// Set up the left frame
if (leftFrame != null) {
leftFrame.setVisibility(View.VISIBLE);
leftFrame.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 3));
}
// Set up the right frame
if (rightFrame != null) {
rightFrame.setVisibility(View.VISIBLE);
rightFrame.setLayoutParams(new LayoutParams(0, LayoutParams.FILL_PARENT, 7));
}
// TODO: set up animation
// Start the transition
commitTransition();
}
希望有所帮助! --randy
答案 1 :(得分:2)
我认为您可以使用3个FrameLayouts并隐藏未使用的帧。所以最初项目框架是隐藏的。在“文件夹”框中选择项目时,“帐户”框架将被隐藏,并且“项目”框架将可见。文件夹框架(或主要活动)必须拦截后退按钮,以便它可以隐藏项目框架并使帐户框架可见。
答案 2 :(得分:1)
我认为你可以从StackScrollView获得一些关于 Android 的想法..