ViewPager标题没有出现,直到我刷卡它 [英] ViewPager Title doesn't appear until I swipe it
问题描述
我学习使用ViewPager和PagerTabStrip实现导航栏。我已经实现了,我的问题是:我每次打开应用程序清新,标题不显示,但经过我刷了一次,标题都再次出现,然后一切正常。 如下图所示code:
I am learning to use ViewPager and PagerTabStrip to implement navigation bar. I have implemented it, my problem is: every time I open the app fresh, the titles don't show, but after I swipe it once, the titles all appear again, and then everything is normal. code shown below:
专项适配器
public class MyPagerAdapter extends PagerAdapter {
private List<View> viewList;
private List<String> titleList;
public MyPagerAdapter(List<View> viewList, List<String> titleList){
this.viewList = viewList;
this.titleList = titleList;
}
@Override
public int getCount() {
return viewList.size();
}
@Override
public boolean isViewFromObject(View view, Object o) {
return view == o;
}
@Override
public Object instantiateItem(ViewGroup container, int position) {
container.addView(viewList.get(position));
return viewList.get(position);
}
@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(viewList.get(position));
}
@Override
public CharSequence getPageTitle(int position) {
return titleList.get(position);
}
}
.xml文件:
.xml File:
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<android.support.v4.view.PagerTabStrip
android:id="@+id/tab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
/>
</android.support.v4.view.ViewPager>
This is the screenshot of "Just clicked the app icon":
And this is after I swiped to the second page:
我真的很沮丧。谢谢!
推荐答案
这是一个问题出现在com.android.support:appcompat-v7:23.0.0 。在这里你可以参考的https://$c$c.google .COM / P /安卓/问题/详细信息?ID = 183127
It is an issue appeared in com.android.support:appcompat-v7:23.0.0. You can refer here https://code.google.com/p/android/issues/detail?id=183127
在该链接谷歌的支持团队必须提到的缺陷将被固定在未来的版本。 所以现在的解决方案是使用生成项目com.android.support:appcompat-v7:22.2.1
In that link google support team have mention that defect would be fixed in future releases. So for now solution is build the project using com.android.support:appcompat-v7:22.2.1
更新:如果可行的你,那么你可以与@nidheeshdas提供另一种解决方案继续前进。我曾尝试简单的项目;它的工作 @nidheeshdas内活动的onResume()修改的方案
Update : If feasible for you then you can go ahead with another solution provided by @nidheeshdas. I have tried on simple project; it work Modified solution of @nidheeshdas inside onResume() of Activity
viewPager.setCurrentItem(1);
viewPager.postDelayed(new Runnable() {
@Override
public void run() {
viewPager.setCurrentItem(0);
}
},100);
这篇关于ViewPager标题没有出现,直到我刷卡它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!