【问题标题】:app:pstsShouldExpand="true" crashing my apapp:pstsShouldExpand="true" 使我的应用程序崩溃
【发布时间】:2018-05-06 19:08:06
【问题描述】:

大家好,我的 app:pstsShouldExpand="true" 有问题

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>

【问题讨论】:

    标签: java android xml android-studio


    【解决方案1】:

    1) 将您的活动内容视图设置为空的线性布局 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) 以相同的顺序添加滑动选项卡和视图页面到线性布局

      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>
    

    【讨论】:

      猜你喜欢
      • 2018-03-19
      • 2016-09-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-07-25
      • 2020-11-16
      • 1970-01-01
      相关资源
      最近更新 更多