gpt4 book ai didi

android - PagerTabStrip 不显示标题,滑动时会显示时间

转载 作者:行者123 更新时间:2023-11-29 00:07:49 26 4
gpt4 key购买 nike

我是中国人,用谷歌翻译提问,有一些问题想请教您。PagerTabStrip 在开始进入页面的时候没有出现title,当我滑动的时候就显示出来了,怎么一开始它的title就显示出来了?希望有人能解答,谢谢。

这是MainActivity.java

public class MainActivity extends Activity {

List<View> views = new ArrayList<View>();
String[] mTitle = {"left", "current", "right"};
View view1, view2, view3;
ViewPager viewPager;


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

viewPager= (ViewPager) findViewById(R.id.viewpager);

LayoutInflater inflater = (LayoutInflater) this.getSystemService(LAYOUT_INFLATER_SERVICE);

view1 = inflater.inflate(R.layout.left_layout, null);
view2 = inflater.inflate(R.layout.activity_main, null);
view3 = inflater.inflate(R.layout.right_layout, null);

views.add(view1);
views.add(view2);
views.add(view3);

PagerAdapter pagerAdapter=new MyPagerAdapter(mTitle);
viewPager.setAdapter(pagerAdapter);
viewPager.setCurrentItem(1);

}

class MyPagerAdapter extends PagerAdapter {

String [] mTitles;

public MyPagerAdapter(String [] titles){
mTitles=titles;
}

@Override
public int getCount() {
return views.size();
}

@Override
public boolean isViewFromObject(View view, Object object) {
return view == object;
}

@Override
public CharSequence getPageTitle(int position) {
return mTitle[position];
}

@Override
public Object instantiateItem(ViewGroup container, int position) {
return null;
}

@Override
public void destroyItem(ViewGroup container, int position, Object object) {
container.removeView(views.get(position));
}
}

activity_main.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" android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<android.support.v4.view.PagerTabStrip
android:id="@+id/pagertitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
></android.support.v4.view.PagerTabStrip>

</android.support.v4.view.ViewPager>

最佳答案

这是支持库中的错误,请在此处查看另一个问同样问题的问题:ViewPager Title doesn't appear until I swipe it

关于android - PagerTabStrip 不显示标题,滑动时会显示时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32557546/

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