android - 使用 fragment 重现 Honeycomb GMail UI

标签 android android-fragments android-3.0-honeycomb

我正在尝试使用 fragment 重现 Honeycomb GMail UI,但不能。这就是我想要的

初始状态:

+--------+---------------+
|        |               |
|Accounts|   Folders     |
|        |               |
+--------+---------------+

选择文件夹后:

+--------+---------------+
|        |               |
|Folders |   Items       |
|        |               |
+--------+---------------+

其中帐户、文件夹和项目是 fragment 。 (显然后退按钮应该进入初始状态)

我尝试了以下布局:

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

不幸的是,这不起作用,因为我无法将我的文件夹 fragment 从右 Pane 移动到左 Pane ( fragment 只能添加一次)。我可以改为创建新文件夹,但这非常浪费资源,需要仔细的状态管理(尤其是当按下后退按钮时)并且看起来不像我想要的样子。

我尝试使用 3 个 FrameLayout(左、中、右,权重分别为 1、1.6、2.56),但我无法在 fragment 未显示时折叠 FrameLayout。非常感谢任何帮助

最佳答案

按照 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();
}

希望对您有所帮助! --兰迪

关于android - 使用 fragment 重现 Honeycomb GMail UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5811922/

相关文章:

android - 如何为 1.6 和 3.0+ 提供不同的 android 小部件?

android - 抽屉导航图标不显示 android

android - 滚动选项卡中的 fragment 时隐藏/显示工具栏

android - 当应用程序在后台时从通知中打开 fragment

android - Fragments、Parcelable 对象和 Back Stack

android - 如何在 ActionBar 中将小指示器三角形设置为自定义操作?

javascript - Android 上 HTML5 网页中的 js 包含文件数量有限

android - 服务中的唤醒锁实现

android - 返回 ListView 时保持/保存/恢复滚动位置

android - 如何在 Activity 中的 API 调用上从 ViewModel 获取错误?