为什么我的smartTabLayout没有显示正确的方法

时间:2017-11-28 15:57:06

标签: android android-layout

我导入了流行的图书馆smartTabLayout,并面临一个问题。

gradle代码是:

compile 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'

我的活动只是找到id和setViewPager。但显示错误:

更新,这是我的代码:

public class PictureActivity extends BaseActivity {

@BindView(R.id.viewpager_tab)
SmartTabLayout tab;
@BindView(R.id.viewpager)
ViewPager viewPager;

private FragmentPagerItemAdapter mAdapter;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_picture);
    ButterKnife.bind(this);
    initTab(mock());
}

private void initTab(List<String> list) {
    initViewPager(list);
    tab.setViewPager(viewPager);
}

private void initViewPager(List<String> list) {
    FragmentPagerItems.Creator creator = new FragmentPagerItems.Creator(this);
    for (String type : list) {
       creator.add(FragmentPagerItem.of(type, HomePictureFragment.class));
    }
    mAdapter = new FragmentPagerItemAdapter(getSupportFragmentManager(), creator.create());
    viewPager.setAdapter(mAdapter);
}

}

更新,我的xml:

    <com.ogaclejapan.smarttablayout.SmartTabLayout
         android:id="@+id/viewpager_tab"
         android:layout_width="match_parent"
         android:layout_height="50dp"
         app:stl_defaultTabBackground="@color/white"
         app:stl_defaultTabTextColor="#3b9dff"
         app:stl_defaultTabTextMinWidth="20dp"
         app:stl_defaultTabTextSize="16sp"
         app:stl_distributeEvenly="true" />

enter image description here

实际上,有五个标签,我可以滚动每个片段。

如果我不使用任何属性,它会显示如下:

enter image description here

当我使用像IndicatorTabStrip这样的其他库时,它可以工作:

这是我的xml:

<HorizontalScrollView
    android:layout_width="match_parent"
    android:layout_height="44dp"
    android:background="@color/white"
    android:fillViewport="true"
    android:scrollbars="none">

    <am.widget.indicatortabstrip.IndicatorTabStrip
        android:id="@+id/viewpager_tab"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="center"
        android:textColor="@color/color_main_tabs"
        android:textSize="15sp"
        app:ttsIndicator="@drawable/home_picture_indicator"
        app:ttsTextScale="1.1" />
</HorizontalScrollView>

enter image description here

1 个答案:

答案 0 :(得分:0)

尝试将以下内容添加到xml:

Cannot read property 'nodeType' of undefined
    at s (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:11536)
    at jQuery.fn.init.t.fn.position (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:13371)
    at t.(anonymous function).(anonymous function)._position (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:11:7019)
    at t.(anonymous function).(anonymous function)._position (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:4499)
    at t.(anonymous function).(anonymous function).open (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:11:937)
    at t.(anonymous function).(anonymous function).open (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:4499)
    at HTMLDivElement.<anonymous> (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:5446)
    at Function.each (http://localhost/FIAF.PES.Particuliers/scripts/jquery-3.1.1.js:368:19)
    at jQuery.fn.init.each (http://localhost/FIAF.PES.Particuliers/scripts/jquery-3.1.1.js:157:17)
    at jQuery.fn.init.t.fn.(anonymous function) [as dialog] (http://localhost/FIAF.PES.Particuliers/scripts/jquery-ui.min.js:6:5329)

您也可以尝试通过设置来设置宽度:

<com.ogaclejapan.smarttablayout.SmartTabLayout
    android:id="@+id/viewpager_tab"
    android:layout_width="match_parent"
    android:layout_height="48dp"
    app:stl_distributeEvenly="true"/>