Android多个TAB选项卡切换效果

2019-12-10 18:17:37王旭
易采站长站为您分析Android多个TAB选项卡切换效果的实现代码,感兴趣的小伙伴们可以参考一下  

在前一期中,我们做了悬浮头部的两个tab切换和下拉刷新效果,后来项目中要求改成三个tab,当时就能估量了一下,如果从之前的改,也不是不可以,但是要互相记住的状态就太多了,很容易出现错误。就决定重新实现一下这个效果,为此先写了一个demo,这期间项目都已经又更新了两个版本了。demo还木有变成文章。

之前的版本中是采用了一个可以下拉刷新的listview,之后在listview中添加了两个头部,并且在该布局上的上面用了一个一模一样的切换tab,如果没有看过前面版本的,可以看看前一个版本,Listview多Tab上滑悬浮。

基于上述思路我们先来看看页面布局:main_activity

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://www.easck.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:background="@color/color_gray_eaeaea" >

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

  <LinearLayout
    android:id="@+id/header"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/white"
    android:orientation="vertical" >

    <ImageView
      android:id="@+id/show_event_detail_bg"
      android:layout_width="fill_parent"
      android:layout_height="135dip"
      android:contentDescription="@string/empty"
      android:scaleType="fitXY"
      android:src="@drawable/header_default_bk" />

    <TextView
      android:id="@+id/show_event_detail_desc"
      android:layout_width="wrap_content"
      android:layout_height="104dip"
      android:paddingBottom="24dip"
      android:layout_marginLeft="15dip"
      android:layout_marginRight="15dip"
      android:paddingTop="25dip"
      android:text="@string/head_title_desc"
      android:textColor="@color/color_black_333333"
      android:textSize="14sp" />

    <View style="@style/horizontal_gray_divider" />

    <View style="@style/horizontal_gray_divider" />

    <com.example.refreashtabview.sliding.PagerSlidingTabStrip
      android:id="@+id/show_tabs"
      android:layout_width="match_parent"
      android:layout_height="44dip"
      android:background="@color/white" />
  </LinearLayout>

</RelativeLayout>