|
视图效果
db5104bce737ea0c63a34106cf1c197.png1.添加依赖 implementation 'q.rorbin:VerticalTabLayout:1.2.5'2.XML布局的使用`<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.douwenxuan.view.category.CategoryFragment">
<q.rorbin.verticaltablayout.VerticalTabLayout
android:id="@+id/vTab"
android:layout_alignParentLeft="true"
android:layout_width="80dp"
android:layout_height="match_parent"
android:background="@color/white">
</q.rorbin.verticaltablayout.VerticalTabLayout>
<android.support.v4.view.ViewPager
android:id="@+id/vp_sort"
android:layout_toRightOf="@id/vTab"
android:layout_width="match_parent"
android:layout_height="match_parent">
</android.support.v4.view.ViewPager>
</RelativeLayout> |
3.Java中的书写 从网络上获取数据进行解析,然后进行适配器的书写
public class CategoryFragment extends BaseFragment implements CategoryContract.View {
@BindView(R.id.vTab)
VerticalTabLayout vTab;
@BindView(R.id.vp_sort)
ViewPager vpSort;
Unbinder unbinder;
@Override
protected int getLayout() {
return R.layout.fragment_category;
}
@Override
protected void initView(View view) {
}
@Override
protected void initData() {
((CategoryPresenter)presenter).category();
}
@Override
protected IPresenter createPresenter() {
return new CategoryPresenter();
}
@Override
public void showErrMsg(String err) {
Toast.makeText(getActivity(), err, Toast.LENGTH_SHORT).show();
}
@Override
public void categoryDataReturn(List<CategoryListBean> categoryList) {
final ArrayList<String> tabName = new ArrayList<>();
final ArrayList<Fragment> fragments = new ArrayList<>();
for (int i = 0; i < categoryList.size(); i++) {
fragments.add(new CategoryTabFragment(categoryList.get(i).getName(), categoryList.get(i).getId() + ""));
tabName.add(categoryList.get(i).getName());
}
FragTabAdapter fragTabAdapter = new FragTabAdapter(getChildFragmentManager(), fragments,
tabName);
vpSort.setAdapter(fragTabAdapter);
vTab.setupWithViewPager(vpSort);
}
} |
FragTabAdapter的书写public class FragTabAdapter extends FragmentPagerAdapter {
private ArrayList<Fragment> fragments = new ArrayList<>();
private ArrayList<String> tabName = new ArrayList<>();
public FragTabAdapter(FragmentManager fm, ArrayList<Fragment> fragments, ArrayList<String>
tabName) {
super(fm);
this.fragments = fragments;
this.tabName = tabName;
}
@Override
public Fragment getItem(int i) {
return fragments.get(i);
}
@Override
public int getCount() {
return fragments.size();
}
@Nullable
@Override
public CharSequence getPageTitle(int position) {
return tabName.get(position);
}
} |
原文链接:https://www.jianshu.com/p/f09d6775f84a
程序猿的技术大观园:www.javathinker.net
[这个贴子最后由 admin 在 2020-01-01 16:12:01 重新编辑]
|
网站系统异常
系统异常信息 |
Request URL:
http://www.javathinker.net/WEB-INF/lybbs/jsp/topic.jsp?postID=1116
java.lang.NullPointerException
如果你不知道错误发生的原因,请把上面完整的信息提交给本站管理人员。
|
|