gpt4 book ai didi

android - 使用 fragment 重现 Honeycomb GMail UI

转载 作者:塔克拉玛干 更新时间:2023-11-02 19:26:11 25 4
gpt4 key购买 nike

我正在尝试使用 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com