gpt4 book ai didi

使用 Swipe View 和 Tile Strip 的 Android 布局

转载 作者:行者123 更新时间:2023-11-29 16:12:52 25 4
gpt4 key购买 nike

我正在制作一个新应用,使用“滑动 View + 平铺 strip ”布局,但似乎无法弄清楚如何将不同的 View 实际加载到 FragmentPagerAdapter 的 fragment 中?

任何帮助都会很棒(我对 Android 开发还是很陌生,所以放轻松 ;))

最佳答案

创建一个扩展 FragmentPagerAdapter 的类。

覆盖 getItem() 并为每个位置返回不同的 fragment 。

尝试这样的事情:

public class MyCustomFPAdapter extends FragmentPagerAdapter{

public MyCustomFPAdapter (FragmentManager fm) {
super(fm);
}

@Override
public Fragment getItem(int position) {
if (position == 0) {
return Fragment0.newInstance();
} else if (position == 1) {
return Fragment1.newInstance();
} else if (position == 2) {
return Fragment2.newInstance();
} else if (position == 3) {
return Fragment3.newInstance();
} else {
return DefaultFragment.newInstance();
}
}
}

关于使用 Swipe View 和 Tile Strip 的 Android 布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11651939/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com