【界面优化】使用viewpagerindicator添加下划线滑动动画
开源代码viewpagerindicator里面没有实现tab下划线切换过程中的移动动画,都是很突兀的多个fragement之间的切换,导致用户体验略差,google了下相关问题,发现一片博文:
public class UnderlinePageIndicatorEx extends UnderlinePageIndicator{
public UnderlinePageIndicatorEx(Context context) {
super(context, null); }
public UnderlinePageIndicatorEx(Context context, AttributeSet attrs) {
super(context, attrs, R.attr.vpiUnderlinePageIndicatorStyle); }
public UnderlinePageIndicatorEx(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle); } @Override
public void setViewPager(ViewPager viewPager) {
if (mViewPager == viewPager) {
return;
}
// if (mViewPager != null) {
// //Clear us from the old pager.
// mViewPager.setOnPageChangeListener(null);
// }
if (viewPager.getAdapter() == null) {
throw new IllegalStateException("ViewPager does not have adapter instance.");
}
mViewPager = viewPager;
// mViewPager.setOnPageChangeListener(this);
invalidate();
post(new Runnable() {
@Override public void run() {
if (mFades) {
post(mFadeRunnable);
}
}
});
}
}
/**
* Draws a line for each page. The current page line is colored differently
* than the unselected page lines.
*/
android:theme="@style/StyledIndicators",对应styles文件下面:
<!-- 下面带横线tab的style -->
<style name="StyledIndicators" parent="@android:style/Theme.Light">
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
</style>
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator">
<!-- <item name="android:background">@drawable/tab_indicator</item> -->
<item name="android:background">#00000000</item>
<item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
<item name="android:textSize">14sp</item>
<item name="android:textColor">@drawable/viewpager_title_textcolor</item>
<item name="android:dividerPadding">8dp</item>
<item name="android:showDividers">middle</item>
<item name="android:paddingLeft">10dp</item>
<item name="android:paddingRight">10dp</item>
<item name="android:fadingEdge">horizontal</item>
<item name="android:fadingEdgeLength">8dp</item>
</style>
<item name="android:background">@drawable/tab_indicator</item>
对应的drawable中切换的xml代码:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<item android:state_selected="false" android:state_pressed="true" android:drawable="@android:color/transparent" />
<item android:state_selected="true" android:state_pressed="false" android:drawable="@drawable/base_tabpager_indicator_selected" />
<item android:state_selected="true" android:state_pressed="true" android:drawable="@drawable/base_tabpager_indicator_selected" />
</selector>

<itemname="android:background">#00000000</item>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<com.soyoungboy.view.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="45dp"
android:background="@color/white" />
<com.soyoungboy.view.viewpagerindicator.UnderlinePageIndicatorEx
android:id="@+id/underline_indicator"
android:layout_width="fill_parent"
android:layout_height="3dp"
/>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
//1,声明组件
private UnderlinePageIndicatorEx mUnderlinePageIndicator;
//2,代码实现部分
mUnderlinePageIndicator = (UnderlinePageIndicatorEx) findViewById(R.id.underline_indicator);
mUnderlinePageIndicator.setViewPager(viewpager);
mUnderlinePageIndicator.setFades(false);
indicator.setOnPageChangeListener(mUnderlinePageIndicator);
【界面优化】使用viewpagerindicator添加下划线滑动动画的更多相关文章
- iOS开发-UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选择 ...
- vim显示行号、语法高亮、自动缩进、添加下划线的设置
ubuntu默认是没有安装vim的,所以设置以前请先安装vim:sudo apt-get install vim. 然后 打开vim的配置文件:sudo vim /etc/vim/vimrc 或者 s ...
- Android 给EditText添加下划线
在安卓高版本,默认是有下划线的,其默认下划线的颜色是由其主题颜色来控制的! 控制如下: <style name="AppTheme" parent="Theme.A ...
- IOS UIlabel 、UIButton添加下划线
1.给UILabel 添加下划线 UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(, , , )]; label.backgrou ...
- UILabel和UIButton添加下划线
关于UILabel和UIButton有的时候需要添加下划线,一般有两种方式通过默认的 NSMutableAttributedString设置,第二种就是在drawRect中画一条下划线,本文就简单的选 ...
- "为文本添加下划线"组件:<u> —— 快应用组件库H-UI
 <import name="u" src="../Common/ui/h-ui/text/c_tag_underline"></impor ...
- TextView 为部分文字添加下划线,并实现单击事件
在开发应用的过程中经常会遇到显示一些不同的字体风格的信息,如关键词高亮显示的等.对于类似的情况,一般我们会想着使用多个TextView去实现,对于每个TextView设置不同的字体风格来满足需求. ...
- [UGUI]图文混排(五):添加下划线
0.下划线标签 标签格式:<material=underline c=#ffffff h=1 n=*** p=***>blablabla...</material> mater ...
- SpringData JPA 在解析实体类字段时驼峰自动添加下划线问题
参考地址:https://my.oschina.net/javamaster/blog/2246886 SpringData JPA 使用的默认命名策略是: ImprovedNamingStrateg ...
随机推荐
- Mvc分页组件MvcSimplePager代码重构
1 Mvc分页组件MvcSimplePager代码重构 1.1 Intro 1.2 MvcSimplePager 代码优化 1.3 MvcSimplePager 使用 1.4 End Mvc分页组件M ...
- Tomcat v7.0 Server at localhost are already in use,tomcat提示端口被占用,tomcat端口已经被使用,tomcat端口占用
Tomcat v7.0 Server at localhost are already in use, tomcat提示端口被占用,tomcat端口已经被使用 >>>>> ...
- MVC源码分析 - Controller创建和创建扩展
上一篇, 出现了一个至关重要的类:MvcHandler, 接下来就来看一下MvcHandler吧. 先不看具体方法, 先看一下类里面的情况. //这里实现了两个重要的接口, 异步处理和同步处理的接口p ...
- Kattis - Peragrams
Peragrams Photo by Ross Beresford Per recently learned about palindromes. Now he wants to tell us ab ...
- node-canvas
1.使用之前需要预先安装 Cairo 本人安装遇到各种各样的坑,可以参考这里来填坑:https://github.com/Automattic/node-canvas/wiki/Installati ...
- Front-End(二)——HTML
本文主要对html迭代学习中的要点.冷点简述罗列. html之前也说过,主要为了描述页面的结构和内容,合理使用结构化的标签,<h1>.<div>等,有利于前端开发,也有利于搜索 ...
- SAP HANA 中的决策表(Decision Table)
http://scn.sap.com/community/developer-center/hana/blog/2013/01/11/what-can-you-do-with-decision-tab ...
- U3D音频系统
一.基本信息 1.支持的声音格式 WAV OGG MP3 AIFF MOD S3M xm IT 导入以后,unity会选择的压缩方式: WAV:无损,音质好,文件大,适用于较短文件 OGG.MP ...
- 【转】gcc/g++ 如何支持c11 / c++11标准编译
如果用命令 g++ -g -Wall main.cpp 编译以下代码 : 1 2 3 4 5 6 7 8 9 10 11 12 /* file : main.cpp */ #include ...
- xml动态修改 dom4j修改
xml的动态修改需要传入的参数 xml的位置(tomcat中的发布位置).修改后的xml需要保存的位置(因为动态修改,所以建议和xml未修改前的位置相同).添加的节点的信息.或者修改的节点的信息 SA ...