[英]android.support.v4.view.ViewPager cannot be cast to android.support.design.widget.TabLayout
When i connect Tablayout and view pager it causes my app to crash i'm using the latest version of the android support library. 当我连接Tablayout并查看寻呼机时,它导致我的应用程序崩溃,我使用的是最新版本的android支持库。 How else would i go about making an app with sliding tabs. 我还要如何制作带有滑动标签的应用程序。
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
PagerAdapter pagerAdapter =
new PagerAdapter(getSupportFragmentManager(),MainActivity.this);
viewPager.setAdapter(pagerAdapter);
TabLayout tabLayout = (TabLayout) findViewById(R.id.pager);
It happens because you are using the same id
to find the ViewPager
and the TabLayout.
发生这种情况是因为您使用相同的id
来查找ViewPager
和TabLayout.
ViewPager viewPager = (ViewPager) findViewById(R.id.pager);
TabLayout tabLayout = (TabLayout) findViewById(R.id.pager);
In your layout check the right id for the TabLayout. 在您的布局中,检查TabLayout的正确ID。
I fixed the layout by changing the width of CoordinatorLayout to wrap_content and changing the width and height of view pager to wrap_content. 我通过将CoordinatorLayout的宽度更改为wrap_content并将视图分页器的宽度和高度更改为wrap_content来修复了布局。 I also gave TabLayout its own id. 我还给了TabLayout自己的ID。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.