我有两个 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/