项目git地址:https://github.com/lantian0314/ndkDemo
SmartTabLayout实现viewpgaer页面导航效果,简化并实现android的TabHost效果,顶部滑动tab,引导页,可以自定义tab样式,过渡效果 实现网易tab,微博tab,微信tab等so easy。 集成了SpringIndicator拖拽效果
开源项目的git地址:https://github.com/ogaclejapan/SmartTabLayout
第一、配置build.gradle文件
compile 'com.ogaclejapan.smarttablayout:library:1.6.1@aar'
//Optional: see how to use the utility.
compile 'com.ogaclejapan.smarttablayout:utils-v4:1.6.1@aar'
第二、Layout界面布局
2.1 samrttable布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.ogaclejapan.smarttablayout.SmartTabLayout
android:id="@+id/viewpagertab"
android:layout_width="match_parent"
android:layout_height="48dp"
app:stl_indicatorAlwaysInCenter="false"
app:stl_indicatorWithoutPadding="false"
app:stl_indicatorInFront="false"
app:stl_indicatorInterpolation="smart"
app:stl_indicatorGravity="bottom"
app:stl_indicatorColor="#40C4FF"
app:stl_indicatorThickness="4dp"
app:stl_indicatorWidth="auto"
app:stl_indicatorCornerRadius="2dp"
app:stl_overlineColor="#4D000000"
app:stl_overlineThickness="0dp"
app:stl_underlineColor="#4D000000"
app:stl_underlineThickness="1dp"
app:stl_dividerColor="#4D000000"
app:stl_dividerThickness="1dp"
app:stl_defaultTabBackground="?attr/selectableItemBackground"
app:stl_defaultTabTextAllCaps="true"
app:stl_defaultTabTextColor="#FC000000"
app:stl_defaultTabTextSize="12sp"
app:stl_defaultTabTextHorizontalPadding="16dp"
app:stl_defaultTabTextMinWidth="0dp"
app:stl_distributeEvenly="false"
app:stl_clickable="true"
app:stl_titleOffset="24dp"
app:stl_drawDecorationAfterTab="false"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/viewpagertab"
/>
</LinearLayout>
2.1 smart_fragment.xml 布局
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/txt_itemtitle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
第三、Activity
public class SmartTable extends AppCompatActivity {
@BindView(R.id.viewpager)
ViewPager viewPager;
@BindView(R.id.viewpagertab)
SmartTabLayout smartTabLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.smarttable);
ButterKnife.bind(this);
FragmentPagerItemAdapter adapter = new FragmentPagerItemAdapter(
getSupportFragmentManager(), FragmentPagerItems.with(this)
.add(R.string.message, SmartFragment.class)
.add(R.string.dynamic, SmartFragment.class)
.add(R.string.contact, SmartFragment.class)
.add(R.string.message, SmartFragment.class)
.add(R.string.dynamic, SmartFragment.class)
.add(R.string.contact,SmartFragment.class)
.create());
viewPager.setAdapter(adapter);
smartTabLayout.setViewPager(viewPager);
}
public class SmartFragment extends Fragment {
TextView txt_itemtitle;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
return inflater.inflate(R.layout.smart_fragment, container, false);
}
@Override
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
int position = FragmentPagerItem.getPosition(getArguments());
txt_itemtitle = (TextView) view.findViewById(R.id.txt_itemtitle);
txt_itemtitle.setText(String.valueOf(position));
}
}