【界面优化】使用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 ...
随机推荐
- CSS预处理器的对比 — Sass、Less和Stylus
本文根据Johnathan Croom的<sass vs. less vs. stylus: Preprocessor Shootout>所译,整个译文带有我们自己的理解与思想,如果译得不 ...
- openresty 前端开发轻量级MVC框架封装一(控制器篇)
通过前面几章,我们已经掌握了一些基本的开发知识,但是代码结构比较简单,缺乏统一的标准,模块化,也缺乏统一的异常处理,这一章我们主要来学习如何封装一个轻量级的MVC框架,规范以及简化开发,并且提供类似p ...
- TypeScript开发ReactNative之fetch函数的提示问题
使用TypeScript开发ReactNative时,发现在类中调用 fetch 函数时IDE可能会提示找不到,无法加载,特别是当类中存在同名的 fetch 成员方法时更是郁闷了,虽然程序是可以执行的 ...
- (三)Harbor使用OpenLDAP认证登陆
接上一篇<安装Harbor>,安装好之后,接下来我们使用OpenLDAP来进行Harbor web界面的登陆验证及权限分配! OpenLDAP: 使用OpenLDAP的都知道,这是一个集 ...
- 关于++i和i++
这个东西我忘了好几次了,啊啊啊,难道是没真正理解吗<script> window.onload=function(){ var i=0; var a=++i; alert(a); }< ...
- Python网络编程学习_Day10
一.进程与线程 1.区别 进程:一个程序要运行时所需要的所有资源的集合,进程是资源的集合. 一个进程至少需要一个线程,这个线程称为主线程 一个进程里面可以有多个线程 两个进程之间的数据是完全独立,不能 ...
- Graph - leetcode [图]
207. Course Schedule 有向图的环检测 bool canFinish(int numCourses, vector<pair<int, int>>& ...
- Rails 执行 rails server 报错 Could not find a JavaScript runtime
gem install 'execj' gem install 'therubyrace' Ubuntu install Node.js(ubuntu) sudo apt-get install no ...
- CodeForces 689E Mike and Geometry Problem
离散化,树状数组,组合数学. 这题的大致思路和$HDU$ $5700$一样.都是求区间交的问题.可以用树状数组维护一下. 这题的话只要计算每一个$i$被统计了几次,假设第$i$点被统计了$ans[i] ...
- python流程控制:while循环
python编程中whihe语句用于循环执行程序,即在某条件下,循环执行某段程序,以处理需要重复处理的相同任务. while循环语句格式: while <判断条件>: 执行语句 count ...