我有几个唯一的fragments
,并且我希望能够在它们之间滚动。唯一的问题是我想根据用户的喜好打开和关闭它们(并更改其顺序)。
我已经有ArrayList
个字符串,然后可以用来查找哪个fragments
需要加载和哪个顺序。
我的问题是,根据我的研究,无法制作出接受recycler adapter
的{{1}}或scrollable view
。
答案 0 :(得分:0)
答案 1 :(得分:0)
因此,如果您希望在片段列表之间进行平滑滚动(这意味着您不需要查看寻呼机),这就是我发现的最佳方法。有点破烂,但对我来说效果很好。
我有足够的framelayouts
来应付我需要的fragments
。然后,将它们设置为所需的片段。
private void LoadFragments() {
mainActiveTools = loadActiveTools();
frameLayouts = loadFrameLayouts();
fragments = loadFragments();
android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
int i = 0;
while(i != frameLayouts.size()) {
int currentFrame = frameLayouts.get(i);
try {
android.support.v4.app.Fragment currentFrag = fragments.get(i);
transaction.replace(currentFrame, currentFrag);
findViewById(currentFrame).setVisibility(View.VISIBLE);
}
catch (IndexOutOfBoundsException e) {
findViewById(currentFrame).setVisibility(View.INVISIBLE);
}
i++;
}
transaction.commit();
}
此代码尝试填写存储在所述framelayouts
中的我的5 ArrayList
中的每一个。实例化一个transaction
,然后一个while loop
给每个framelayouts
一个fragment
。此外,还会明确告知每个framelayout
是否为visible
。
现在我是Java / Android编程的初学者,但是至少对我来说,这可以完成工作。既不知道它的可扩展性(我猜想直到您对复制粘贴无聊或应用程序崩溃为止),也不管它是否对您有用,这对性能的影响也不大!