在PagerTabStrip文字在第一视图不显示视图、文字、PagerTabStrip

2023-09-07 03:15:22 作者:最后一颗心

我有以下简单的设置:

swipeable.xml

swipeable.xml

<LinearLayout
    android:id="@+id/content_frame"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <include layout="@layout/toolbar" />

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <android.support.v4.view.PagerTabStrip
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
    </android.support.v4.view.ViewPager>
</LinearLayout>

活动:

public class InfoActivity extends ActionBarActivity {

  private static final int[][] KEYS = { { R.string.usage, R.string.usage_text }, 
                                        { R.string.data_protection, R.string.data_protection_text }, 
                                        { R.string.impressum, R.string.impressum_text } };

  @Override
  protected void onCreate( Bundle savedInstanceState ) {
    setContentView( R.layout.swipeable );
    super.onCreate( savedInstanceState );
    ViewPager viewPager = (ViewPager)findViewById( R.id.pager );
    viewPager.setAdapter( new SwipeAdapter( getSupportFragmentManager() ) );
  }

  class SwipeAdapter extends FragmentStatePagerAdapter {

    public SwipeAdapter( FragmentManager fm ) {
      super( fm );
    }

    @Override
    public Fragment getItem( int position ) {
      Bundle b = new Bundle();
      b.putInt( "key", KEYS[ position ][ 1 ] );
      return Fragment.instantiate( InfoActivity.this, InfoFragment.class.getName(), b );
    }

    @Override
    public int getCount() {
      return KEYS.length;
    }

    @Override
    public CharSequence getPageTitle( int position ) {
      return getString( KEYS[ position ][ 0 ] ).toUpperCase();
    }
  }      
}

如果我访问活动的第一时间,没有pagerstrip,文本显示。如果我刷或单击该选项卡,在文本显示正常:

If I access the activity the 1st time, no pagerstrip-texts are shown. If I swipe or click the tab, the texts are displayed normally:

可能是什么这样一个奇怪的现象的原因?

What could be the reason for such a strange behavior?

推荐答案

对于我这个问题发生后,我更新了支持-V13 (或 V4 ), appcompat-V7 recyclerview-V7 设计 23.0.0 。我想这是一个错误。它降级到 22.2.1 后,工作正常。

For me this issue happened after I updated the support-v13 (or v4), appcompat-v7, recyclerview-v7 and design libraries to 23.0.0. I guess it is a bug. After downgrading it to 22.2.1, it is working fine.

我会建议等到他们释放这些库的新版本。

I would suggest to wait until they release new revision of these libraries.

更新::此问题只发生在 appcompat-V7 设计库,目前已得到修复 23.1.0 Android的支持库的版本。

Update: This issue is occurring only in appcompat-v7 and design libs, which has now got fixed in 23.1.0 revision of Android Support Library.