android - 添加了向下滚动的 fragment

标签 android android-fragments android-scrollview

我有两个 fragment ,第一个 fragment 包含线性布局列表,整个 fragment 在 ScrollView 中,添加第二个 fragment ,第一个 fragment 隐藏在从第一个 fragment 中选择项目时。 问题是,如果第一个 fragment 向下滚动,则第二个 fragment 会向下滚动。 我尝试了强制第二个 fragment 滚动到 (0,0) 的方法,但失败了。

用于添加第二个 fragment 的代码

public void setActionOnClick(String id) {
     CommentFragment frag = new CommentFragment();
     Bundle bundle = new Bundle();
     bundle.putString("id", id);
     bundle.putString("TAG", TAG_NEWS_STORY);
     ((MainActivity) getActivity()).setCurrentTag(TAG_NEWS_STORY);
     frag.setArguments(bundle);
     android.support.v4.app.FragmentTransaction fragmentTransaction = 
     getActivity().getSupportFragmentManager().beginTransaction();
     fragmentTransaction.setCustomAnimations(android.R.anim.fade_in, 
     android.R.anim.fade_out);
     fragmentTransaction.add(R.id.main_content, frag, TAG_NEWS_STORY);
     fragmentTransaction.addToBackStack(null);
     fragmentTransaction.commit();
}

在附加第二个 fragment 时,第一个 fragment 被隐藏。 我不想使用 fragmentTransaction.replace,因为我不想重新加载对 api 的调用。

最佳答案

这是一个老问题但是。可能您的 fragment place_hoder 在 ScrollView 中。 只需检查 R.id.main_content 是否在 ScrollView 中。 您应该将 ScrollView 添加到 fragment-layout 而不是在其中实例化 fragment

关于android - 添加了向下滚动的 fragment ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47281512/

相关文章:

android - 火库 : PERMISSION_DENIED: Missing or insufficient permissions

Android应用许可只是一段时间

Android - 自定义操作栏 sherlock 选项卡

Android - 如何阻止 fragment 自动恢复其状态?

java - 如何在没有动画的情况下滚动到 ScrollView 中的某个位置?

java - 将 firebase 添加到应用程序时出现 appcompat 依赖项错误

android - 如何在抽屉导航布局中添加图像标题

android - 在 fragment 中使用 Butterknife 时绑定(bind) View 为空

android - ScrollView 在约束布局内不起作用

java - Android - 如何检测屏幕上的触摸是 "scroll"触摸?