我有3步应用程序^1步用户选择他需要什么,例如:-Cars -Buildings .
2步骤-单击项目后需要显示汽车、建筑或其他东西的列表;3步骤-显示项目的详细信息。
例子:1步-汽车-> 2步-马自达someModel -> 3步-详细型号
now..can你推荐我正确的方法:在智能手机上,一个片段将被替换为另一个在平板电脑上如何做:1步骤-1片段-类型列表-汽车-建筑.
2步骤-2片段-类型列表和选定类型的项目列表
3步骤-2片段-选择后的项目列表和项目详细信息
我希望能清楚地解释我想要什么;
我知道的一些方法:1-创建水平线性布局并添加/替换/删除片段2-创建布局,其中包括2个framelayout(对于每个片段),并显示/隐藏第二个片段.
发布于 2014-12-30 13:47:03
您只需在您的活动中有一个FrameLayout,并在此FrameLayout中为每个步骤替换片段。您甚至可以自定义动画。
编辑:对于平板电脑,您可以拥有一个水平的LinearLayout。如果您希望左片段(类型列表或项列表)获取屏幕的1/3,而右侧片段(项目列表或详细信息列表)获取屏幕的2/3,则可以使用LinearLayout的加权属性。
在步骤1中,您的LinearLayout只包含一个weight为1的FrameLayout,这将是全屏。
当您切换到步骤2时,您不会替换第一个容器中的片段,您只需通过编程方式将一个新的FrameLayout容器添加到一个weight为2的容器中,这两个容器都将占用所需的大量空间。
要动态设置视图的权重,必须编辑视图的LayoutParams:
ViewGroup rightContainer = new FrameLayout(this);
rightContainer.setId(View.generateViewId()); // you need an ID to perform a fragment transaction
// api 17+ only, use static ID or copy/paste the code for lower platform
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(0, ViewGroup.LayoutParams.MATCH_PARENT, 2); // the last param is the weight
rightContainer.setLayoutParams(lp);
linearLayout.addView(rightContainer);
fragmentManager.beginTransaction()
.add(rightContainer.getId(), ItemListFragment.newInstance(), "ITEM_LIST")
// add custom transition if needed
.commit();当您切换到步骤3时,只需替换第二个容器中的片段以显示细节,并替换第一个容器中的片段以显示项目列表。
如果您不想重新创建片段并重用旧实例,那么如果使用标记将片段添加到FragmentManager中,则可以逐个检索片段。
ItemListFragment oldFragment = fragmentManager.findFragmentByTag("ITEM_LIST");
DetailFragment detailFragment = DetailFragment.newInstance();
fragmentManager.beginTransaction()
.replace(leftContainer.getId(), oldFragment, "ITEM_LIST")
.replace(rightContainer.getId(), detailFragment, "DETAIL")
.commit();https://stackoverflow.com/questions/27706416
复制相似问题