大家好我有roblem whit app:pstsShouldExpand =“true”in
com.astuetz.PagerSlidingTabStrip
当我从我的布局中删除com.astuetz.PagerSlidingTabStrip时!它的工作完美,但当我使用(app:pstsShouldExpand =“true”)我的应用程序崩溃
这是我的布局
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<android.support.v7.widget.Toolbar
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="@color/colorPrimary">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/img_login"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_gravity="right"
android:layout_marginRight="5dp"
android:layout_marginTop="4dp"
android:onClick="on_img_login_click"
android:src="@drawable/ic_account_circle_black_24dp"/>
</LinearLayout>
</android.support.v7.widget.Toolbar>
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="48dip"
app:pstsShouldExpand="true"
/>
<android.support.v4.view.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/pager"
>
</android.support.v4.view.ViewPager>
</LinearLayout>
答案 0 :(得分:0)
1)将您的活动内容视图设置为清空linearlayout XMLfile
setContentView(R.layout.pagerslidingtabstrip_viewpager);
2)找到布局并将其保存在变量
中 LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout_view);
3)从单独的XLM文件中扩展viewpager,而不是仅包含viewpager元素
mLayoutInflater = getLayoutInflater();
mInflatedViewPagerLayout = mLayoutInflater.inflate(R.layout.separate_viewpager,null);
mViewPager = mInflatedViewPagerLayout.findViewById(R.id.viewpager);
4)从代码
创建和配置滑动标签mTabStripLayout = new PagerSlidingTabStrip(this);
mTabStripLayout.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 140));
mTabStripLayout.setShouldExpand(true);
mTabStripLayout.setAllCaps(true);
mTabStripLayout.setTextSize(60);
mTabStripLayout.setTextColor(Color.BLACK);
mTabStripLayout.setDividerColor(Color.BLUE);
mTabStripLayout.setDividerPadding(30);
mTabStripLayout.setIndicatorColor(Color.RED);
mTabStripLayout.setIndicatorHeight(15);
mTabStripLayout.setUnderlineColor(Color.BLUE);
4)以相同的顺序添加滑动标签和viewpager到linearlayout
mainLayout.addView(mTabStripLayout);
mainLayout.addView(mViewPager);
5)像往常一样完成剩余设置,例如创建适配器,将适配器分配给
viewpager, and assigning viewpager to sliding tabs
mPagerAdapter = new SampleFragmentPagerAdapter(getSupportFragmentManager());
mViewPager.setAdapter(mPagerAdapter);
mTabStripLayout.setViewPager(mViewPager);
或xml
<com.astuetz.PagerSlidingTabStrip
android:id="@+id/tabs"
app:pstsShouldExpand="true"
android:layout_width="match_parent"
android:layout_height="48dp"
android:textSize="14sp"
android:textColor="#000000"
app:pstsDividerColor="@color/green"
app:pstsIndicatorColor="@color/red"
app:pstsUnderlineColor="@color/blue"
app:pstsTabPaddingLeftRight="14dp">
</com.astuetz.PagerSlidingTabStrip>