背景
不多说,直接看此图。

关键技术
ViewPager有个setPageTransformer方法可以设置页面切换时的动画:
public void setPageTransformer(boolean reverseDrawingOrder, PageTransformer transformer)
/**
* 自定义Pager切换模式
*/
class DefaultTransformer implements ViewPager.PageTransformer {
@Override
public void transformPage(View view, float position) {
float alpha = 0;
if (0 <= position && position <= 1) {
alpha = 1 - position;
} else if (-1 < position && position < 0) {
alpha = position + 1;
}
view.setAlpha(alpha);
view.setTranslationX(view.getWidth() * -position);
float yPosition = position * view.getHeight();
view.setTranslationY(yPosition);
}
}
跑马灯TextView:
public class MarqueeText extends TextView {
public MarqueeText(Context context, AttributeSet attrs) {
super(context, attrs);
}
@Override
protected void onFocusChanged(boolean focused, int direction, Rect previouslyFocusedRect) {
super.onFocusChanged(focused, direction, previouslyFocusedRect);
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
if(hasWindowFocus) super.onWindowFocusChanged(hasWindowFocus);
}
@Override
@ViewDebug.ExportedProperty(category = "focus")
public boolean isFocused() {
return true;
}
}
代码地址在GitHub:地址
网友评论