sách gpt4 ai đã đi

旋转手机时Android隐藏 fragment 内容

In lại 作者:行者123 更新时间:2023-11-30 01:58:22 35 4
mua khóa gpt4 Nike

在我的应用程序中,我使用支持 View 寻呼机和 PagerTabStrip。进入查看寻呼机我有一些 fragment ,进入其中一个我正在使用支持卡片 View 。运行应用程序后,所有卡片 View 项目都正确显示,但将手机从纵向旋转到横向后,内容隐藏。

nhập mô tả hình ảnh ở đây

nhập mô tả hình ảnh ở đây

làm mới:主 Activity

@Ghi đè
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ButterKnife.inject(this);
Globals.setActivity(this);

contentFragment = ContentFragment.newInstance(R.drawable.ic_launcher);
getSupportFragmentManager().beginTransaction()
.replace(R.id.frame_container, contentFragment)
.commit();

current_fragment_id = 0;
updateFragment(current_fragment_id);

drawer_adatper =
new DrawerAdatper(
this, R.layout.drawer_item_layout, R.layout.drawer_item_group_layout, drawer_items);
drawer_list.setAdapter(drawer_adatper);
}

ContentFragment fragment :

public class ContentFragment extends Fragment implements ScreenShotable {

public static ContentFragment newInstance(int page) {
ContentFragment fragmentFirst = new ContentFragment();
Bundle args = new Bundle();
args.putInt("page", page);
fragmentFirst.setArguments(args);
return fragmentFirst;
}

@Ghi đè
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
page = getArguments().getInt("page", 0);
}

@Ghi đè
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.fragment_online_categories, container, false);
ButterKnife.inject(this, view);
initializeUi();
pager_header.setTabIndicatorColor(Color.parseColor(Arrays.asList(pageTabIndicatorColors).get(0)));
BootStrapPagerAdapter adapterViewPager = new BootStrapPagerAdapter(getActivity().getSupportFragmentManager());
quay lại xem;
}

public static class BootStrapPagerAdapter extends FragmentPagerAdapter {
private static int NUM_ITEMS = 8;
public BootStrapPagerAdapter(FragmentManager fragmentManager) {
super(fragmentManager);
}

công khai int getCount() {
return NUM_ITEMS;
}
@Ghi đè
public Fragment getItem(int position) {
switch (position) {
case 0:
return FragmentContactList.newInstance(0);
}
}
@Ghi đè
public CharSequence getPageTitle(int position) {
String title = "";
switch (position) {
case 0:
title = Utils.getString(R.string.section_industry);
phá vỡ;
}
return title;
}
}
}

FragmentContactList:

public class FragmentContactList extends Fragment {
private StackTraceElement[] traceElements = Thread.currentThread().getStackTrace();
private int page;
RecyclerView rv;
private List persons;

public static FragmentContactList newInstance(int page) {
FragmentContactList fragmentFirst = new FragmentContactList();
Bundle args = new Bundle();
args.putInt("page", page);
fragmentFirst.setArguments(args);
return fragmentFirst;
}

@Ghi đè
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
page = getArguments().getInt("page", 0);
}

@Ghi đè
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.recyclerview_activity, container, false);
rv = (RecyclerView) view.findViewById(R.id.rv);

LinearLayoutManager llm = new LinearLayoutManager(getActivity());
rv.setLayoutManager(llm);
rv.setHasFixedSize(true);

initializeData();
initializeAdapter();
quay lại xem;
}

private void initializeData(){
persons = new ArrayList<>();
persons.add(new Person("Emma Wilson", "23 years old", R.drawable.icon_inbox));
persons.add(new Person("Lavery Maiss", "25 years old", R.drawable.icon_inbox));
persons.add(new Person("Lillie Watts", "35 years old", R.drawable.icon_inbox));
}

private void initializeAdapter(){
RVAdapter adapter = new RVAdapter(persons);
rv.setAdapter(adapter);
}
@Ghi đè
public void onResume() {
super.onResume();
getView().invalidate();
}
}

1 Câu trả lời

你应该改变

public static class BootStrapPagerAdapter extends FragmentPagerAdapter

đến

public static class BootStrapPagerAdapter extends FragmentStatePagerAdapter

您可以从这里检查它们之间的区别: Difference between FragmentPagerAdapter and FragmentStatePagerAdapter

关于旋转手机时Android隐藏 fragment 内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31839098/

35 4 0
Bài viết được đề xuất: c++ - XCode 4.6.2 中的 Stanford Engineering Everywhere CS106B C++ 库
Bài viết được đề xuất: c++ - 访问 QTimer 的经过秒数?
Bài viết được đề xuất: c++ - 类模板声明中的类型不匹配
Bài viết được đề xuất: c++ - 模板类中函数的多重定义
行者123
Hồ sơ cá nhân

Tôi là một lập trình viên xuất sắc, rất giỏi!

Nhận phiếu giảm giá Didi Taxi miễn phí
Mã giảm giá Didi Taxi
Giấy chứng nhận ICP Bắc Kinh số 000000
Hợp tác quảng cáo: 1813099741@qq.com 6ren.com