Activity的样式

    <style name="under_live_indicator" parent="android:Theme.NoTitleBar">
        <item name="vpiTabPageIndicatorStyle">@style/main_live_tab_title_style</item>
        <item name="android:windowBackground"> @android:color/transparent</item>
        <item name="android:windowIsTranslucent">false</item>
        <item name="android:windowAnimationStyle">@style/Animation.Activity.Translucent.Style</item>

</style>  


<style name="main_live_tab_title_style" parent="Widget.TabPageIndicator">

        <item name="android:background">@drawable/main_live_tab_selector</item>
        <item name="android:textSize">16sp</item>
        <item name="android:textColor">@color/main_live_indicator_color</item>

</style>


    <style name="Animation.Activity.Translucent.Style" parent="@android:style/Animation.Activity">
        <item name="android:activityOpenEnterAnimation">@anim/slide_in_right</item>
        <item name="android:activityOpenExitAnimation">@anim/slide_out_left</item>
        <item name="android:activityCloseEnterAnimation">@anim/slide_in_left</item>
        <item name="android:activityCloseExitAnimation">@anim/slide_out_right</item>

</style>


页面切换时的补间动画

slide_in_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="300"
        android:fromXDelta="100%p"
        android:toXDelta="0" />
    <alpha
        android:duration="300"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>


slide_out_left

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="300"
        android:fromXDelta="0"
        android:toXDelta="-100%p" />
    <alpha
        android:duration="300"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>


slide_in_left

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="300"
        android:fromXDelta="-100%p"
        android:toXDelta="0" />
    <alpha
        android:duration="300"
        android:fromAlpha="0.0"
        android:toAlpha="1.0" />

</set>


slide_out_right

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
    <translate
        android:duration="300"
        android:fromXDelta="0"
        android:toXDelta="100%p" />
    <alpha
        android:duration="300"
        android:fromAlpha="1.0"
        android:toAlpha="0.0" />

</set>


选择器

main_live_tab_selector,是一张9path图,当获取焦点或选中或点击时显示,否则不显示

<?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
  <item android:state_focused="false" android:state_selected="true"  android:state_pressed="false" android:drawable="@drawable/main_live_tab_bg" />
</selector>

main_live_indicator_color,文字颜色选择器

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_enabled="false" android:color="#a8a8a8"/>
    <item android:state_pressed="true" android:color="#666666"/>
    <item android:state_selected="true" android:color="#666666"/>
    <item android:color="#a8a8a8"/>

</selector>


为Activity设置样式

         <activity
            android:name="com.lokinfo.m95xiu.MarketActivity"
            android:launchMode="singleTop"
            android:screenOrientation="portrait"
            android:theme="@style/under_live_indicator" >

</activity>


Activity代码

public class MarketActivity extends  BaseFragmentActivity{
    private ViewPager vp_charts;
    private TabPageIndicator tpi_charts;
    private MarketFragmentAdapter mAdapter;
    private int firstItem;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        pageName = "商城";
        super.onCreate(savedInstanceState);
        firstItem = getIntent().getIntExtra("item", 0);
        setContentView(R.layout.activity_viewpager);

        TitleBar titleBar = new TitleBar(this);
        titleBar.setViewText("返回", "商城");
        vp_charts = (ViewPager) findViewById(R.id.vp);
        tpi_charts = (TabPageIndicator) findViewById(R.id.tpi);
        mAdapter = new MarketFragmentAdapter(getSupportFragmentManager());
        vp_charts.setAdapter(mAdapter);
        tpi_charts.setViewPager(vp_charts);
        tpi_charts.setCurrentItem(firstItem);
        
        // 改变 TabPageIndicator 里面的字体左右 的padding 距离
        ViewGroup vg = (ViewGroup) tpi_charts.getChildAt(0);
        int vgChildCount = vg.getChildCount();
        for (int j = 0; j < vgChildCount; j++) {
            View vgChild = vg.getChildAt(j);
            if (vgChild instanceof TextView) {
                ((TextView) vgChild).setPadding(10,11,11,11);
            }
        }
    }

}


<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical" >
    <include
        android:id="@+id/title_bar"
        android:layout_width="match_parent"
        android:layout_height="@dimen/title_bar_height"
        android:layout_alignParentTop="true"
        layout="@layout/view_top_bar2" />
    <com.viewpagerindicator.TabPageIndicator
        android:id="@+id/tpi"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/title_bar"
        android:background="@color/white" />
    <android.support.v4.view.ViewPager
        android:id="@+id/vp"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/tpi" />
    <ImageView
        android:id="@+id/iv_bg"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignTop="@id/vp"
        android:background="@drawable/main_bg_top" />

</RelativeLayout>


Adapter代码

public class MarketFragmentAdapter extends FragmentPagerAdapter {
    private List<String> mList;
    public MarketFragmentAdapter(FragmentManager fm) {
        super(fm);
        mList = new ArrayList<String>();
        mList.add("普通VIP");
        mList.add("尊贵VIP");
        mList.add("钻石VIP");
        mList.add("车市");
    }
    @Override
    public Fragment getItem(int position) {
        switch (position) {
        case 0:
            return VipFragment.createVipFragment("VIP");
        case 1:
            return VipFragment.createVipFragment("SVIP");
        case 2:
            return VipFragment.createVipFragment("DVIP");
        case 3:
            return new CarFragment();
        default:
            return null;
        }
    }
    @Override
    public CharSequence getPageTitle(int position) {
        return mList.get(position);
    }
    @Override
    public int getCount() {
        return mList == null ? 0 : mList.size();
    }

}


内容Fragment

public class VipFragment extends BaseFragment implements OnEventListener {
    private NestedGridView gv_vip;
    private List<VipBena> mList;
    private VipAdapter mAdapter;
    private String vipType;
    private TextView tv_vip_time;
    public static VipFragment createVipFragment(String vipType) {
        VipFragment fragment = new VipFragment();
        Bundle bundle = new Bundle();
        bundle.putString("vipType", vipType);
        fragment.setArguments(bundle);
        return fragment;
    }
    @Override
    public void onCreate(Bundle savedInstanceState) {
        Bundle bundle = getArguments();
        if (bundle != null)  vipType = bundle.getString("vipType");
        super.onCreate(savedInstanceState);
        pageName = "vip";
    }
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        view = inflater.inflate(R.layout.fragment_vip, null);
        initView();
        return view;
    }
    private void initView() {
        gv_vip = (NestedGridView) view.findViewById(R.id.gv_vip);
        tv_vip_time = (TextView) view.findViewById(R.id.tv_vip_time);
        updateVipTime();
        mList = new ArrayList<VipBena>();
        if (vipType.equals("DVIP")) {
            mList.addAll(VipManager.getINSTANCE().getDVipList());
            gv_vip.setNumColumns(2);
        } else if (vipType.equals("SVIP")) {
            mList.addAll(VipManager.getINSTANCE().getSVipList());
            gv_vip.setNumColumns(2);
        } else {
            mList.addAll(VipManager.getINSTANCE().getnormalVipList());
            gv_vip.setNumColumns(2);
        }
        mAdapter = new VipAdapter(context, mList, vipType);
        mAdapter.setEventListener(this);
        gv_vip.setAdapter(mAdapter);
    }
    @Override
    public void onResume() {
        updateVipTime();
        super.onResume();
    }
    private void updateVipTime() {
        if (AppUser.getInstance().isLogin()) {
            tv_vip_time.setVisibility(View.VISIBLE);
            switch (AppUser.getInstance().getUser().getVipType()) {
            case 1:
                tv_vip_time.setText("您是普通VIP,剩余" + AppUser.getInstance().getUser().getVipExpires() + "天");
                break;
            case 2:
                tv_vip_time.setText("您是尊贵VIP,剩余" + AppUser.getInstance().getUser().getVipExpires() + "天");
                break;
            case 3:
                tv_vip_time.setText("您是钻石VIP,剩余" + AppUser.getInstance().getUser().getVipExpires() + "天");
                break;
            default:
                tv_vip_time.setText("您还不是会员,开通会员获取特权");
                break;
            }
        } else {
            tv_vip_time.setVisibility(View.GONE);
        }
    }
    /**
     * 购买vip后的回调
     */
    @Override
    public void onEventListener(boolean successed, String msg) {
        if (successed)  updateVipTime();
    }

}


95秀-ViewPager 使用实例的更多相关文章

  1. 仿网易新闻客户端头条ViewPager嵌套实例

    要点: 1.重写组件public boolean onInterceptTouchEvent(MotionEvent event)方法 2.正确使用requestDisallowInterceptTo ...

  2. 95秀-自定义对话框 dialog 合集

    普通的确认对话框 NormalDialog.java import android.app.Dialog; import android.content.Context; import android ...

  3. 95秀-异步http请求完整过程

    最终调用时的代码     private void ansyClearApplyInfor() {         RequestParams params = new RequestParams() ...

  4. 95秀-dialog 进度对话框 实用工具

    工具Util public class DialogUtil {     public static ProgressDialogView progressDialog;     /**      * ...

  5. 95秀-PullToRefreshListView 示例

        正在加载.暂无数据页面 public class RefreshGuideTool {     private RelativeLayout rl_loading_guide;//整个View ...

  6. 95秀-弹窗+listview+动画 示例

    Dialog布局 dialog.xml <?xml version="1.0" encoding="utf-8"?> <RelativeLay ...

  7. 直播【95秀】JNI 基本实现 简洁

    2017-2-8 基本架构 1.使用SurfaceView在UI层面展示视频 2.通过JNI调用C代码控制视频的播放.停止 基本功能 1.从服务器获取正在直播的主播的列表信息 2.进入直播界面 3.可 ...

  8. Android学习记录:ViewPager实现欢迎页

    许多APP在第一次启动的时候,都会有welcome page.近日尝试利用ViewPager来实现Welcome Page. d0711 完成记录,跟新下载地址 =================== ...

  9. ViewPager、Fragment、Matrix综合使用实现Tab滑页效果

    原文地址:http://www.cnblogs.com/kross/p/3372987.html 我们实现一个上面是一个可以左右滑动的页面,下面是三个可点击切换的tab按钮,tab按钮上还有一个激活条 ...

随机推荐

  1. C语言的printf输出格式控制

    C语言的printf输出格式控制 printf大家都耳熟能详,但是能真正将其用法弄透的估计很少见. 转一篇,改天整理. 1.转换说明符 %a(%A)     浮点数.十六进制数字和p-(P-)记数法( ...

  2. interrupt & storage & DMA

    1.Interrupt: The occurrence of an event is usually signaled by aninterrupt from either the hardware ...

  3. C语言零移位操作

    给定一个整形数组要求把其中的零元素移动到数组的末尾 非零元顺序保持不变 以下采用两种方法实现 #include <stdlib.h> #include <stdio.h> #i ...

  4. ExtJS智能提示工具spket安装与破解

    用myeclipse写java程序,最怕的是什么呢,写javascript代码,原因很简单,没有智能提示,ExtJS是完全js代码的界面库,写起来就更痛苦了,幸好有人做了spket插件,此文采用傻瓜式 ...

  5. 【转载】Think as Customer 以客户为中心的测试理念

    纵观各大公司的核心理念,往往都有一条类似“以客户为中心”的价值观.华为公司更是把“以客户为中心”放在其核心价值观的第一条,以显示它的重要性.从我 们入职培训开始,公司就反复强调并引导大家深入讨论,希望 ...

  6. 《asp.net mvc3 高级编程》第三章 视图

    一.视图的作用 视图的职责是向用户提供界面.从ASP.NET MVC3开始,视图数据也可以通过ViewBag属性访问.例如:ViewBag.Message 就等于ViewData["Mess ...

  7. Phaser开源2d引擎 javascript/html5游戏框架

    功能特点(Features) 易维护代码(Easy Asset Loading) Phaser可以加载图片,音频文件,数据文件,文本文件和自动解析精灵图和纹理地图集数据(出口纹理封隔器或Flash C ...

  8. CSS hack技巧

    CSS hack技巧一览,原文来自CSDN freshlover的博客专栏<史上最全CSS Hack方式一览> 什么是CSS hack 由于不同厂商的流览器或某浏览器的不同版本(如IE6- ...

  9. Python新手学习基础之数据结构-序列1

    序列概念 序列,顾名思义就是有顺序的列,在Python里序列类型的数据结构包括字符串,列表和元组.既然都是序列类型,说明他们有很多共通点,他们的每一个元素都可以通过指定的偏移量方式(索引操作)来获得, ...

  10. Lucene查询条数限制

    运用Lucene进行索引,在查询的时候是有条数限制的 public virtual TopFieldDocs Search(Query query, Filter filter, int n, Sor ...