PagerTabStrip 不显示标题,滑动时会显示时间
PagerTabStrip not display the title, the time when you slide will be displayed
我是中国人,用Google翻译提问,有问题想请教您。
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>
这是支持库中的错误,请在此处查看另一个问同样问题的问题:
我是中国人,用Google翻译提问,有问题想请教您。 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>
这是支持库中的错误,请在此处查看另一个问同样问题的问题: