当前位置: 首页 > news >正文

正规网站建设空间什么是优化师

正规网站建设空间,什么是优化师,万江网站建设公司,如何在八戒网便宜做网站之前在实现控件阴影时有提到过,阴影效果的实现采用的是Android原生的View的属性,拔高Z轴。Z轴会让View产生阴影的效果。 Zelevation translationZ 拔高Z轴可以通过控制elevation和translationZ。 我们之前是通过elevation来单纯的控制Z轴;而…

之前在实现控件阴影时有提到过,阴影效果的实现采用的是Android原生的View的属性,拔高Z轴。Z轴会让View产生阴影的效果。

Z=elevation+ translationZ
拔高Z轴可以通过控制elevation和translationZ。
我们之前是通过elevation来单纯的控制Z轴;而translateZ,除了控制Z轴,还可以用来控制动画效果,比如我们点击按钮时希望它有一个弹起的效果,就是借助这个属性来实现。

StateAnimatorView接口

创建一个通用接口:

public interface StateAnimatorView {void setStateAnimator(StateAnimator stateAnimator);StateAnimator getStateAnimator();
}

实现接口

ShapeButton 实现 StateAnimatorView接口:

    // -------------------------------// stateAnimator// -------------------------------private StateAnimator stateAnimator = new StateAnimator(this);@Overridepublic void setStateAnimator(StateAnimator stateAnimator) {this.stateAnimator = stateAnimator;}@Overridepublic StateAnimator getStateAnimator() {return stateAnimator;}

StateAnimator

StateAnimator是一个管理View状态和相关Animator的类:

public class StateAnimator {private final ArrayList<Tuple> mTuples = new ArrayList<>();private Tuple lastMatch = null;private Animator runningAnimation = null;private WeakReference<View> viewRef;public StateAnimator(View target) {setTarget(target);}private Animator.AnimatorListener mAnimationListener = new Animator.AnimatorListener() {@Overridepublic void onAnimationStart(Animator animation) {}@Overridepublic void onAnimationEnd(Animator animation) {if (runningAnimation == animation) {runningAnimation = null;}}@Overridepublic void onAnimationCancel(Animator animation) {}@Overridepublic void onAnimationRepeat(Animator animation) {}};/*** Associates the given Animation with the provided drawable state specs so that it will be run* when the View's drawable state matches the specs.** @param specs     drawable state specs to match against* @param animation The Animation to run when the specs match*/public void addState(int[] specs, Animator animation, Animator.AnimatorListener listener) {Tuple tuple = new Tuple(specs, animation, listener);animation.addListener(mAnimationListener);mTuples.add(tuple);}/*** Returns the current {@link Animation} which is started because of a state change.** @return The currently running Animation or null if no Animation is running*/Animator getRunningAnimation() {return runningAnimation;}View getTarget() {return viewRef == null ? null : viewRef.get();}void setTarget(View view) {final View current = getTarget();if (current == view) {return;}if (current != null) {clearTarget();}if (view != null) {viewRef = new WeakReference<>(view);}}private void clearTarget() {viewRef = null;lastMatch = null;runningAnimation = null;}/*** Called by View*/public void setState(int[] state) {Tuple match = null;final int count = mTuples.size();for (int i = 0; i < count; i++) {final Tuple tuple = mTuples.get(i);if (StateSet.stateSetMatches(tuple.mSpecs, state)) {match = tuple;break;}}if (match == lastMatch) {return;}if (lastMatch != null) {cancel();}lastMatch = match;View view = (View) viewRef.get();if (match != null && view != null && view.getVisibility() == View.VISIBLE) {start(match);}}private void start(Tuple match) {match.getListener().onAnimationStart(match.animation);runningAnimation = match.animation;runningAnimation.start();}private void cancel() {if (runningAnimation != null && runningAnimation.isRunning()) {runningAnimation.cancel();runningAnimation = null;}}/*** @hide*/ArrayList<Tuple> getTuples() {return mTuples;}static class Tuple {final int[] mSpecs;final Animator animation;private Animator.AnimatorListener listener;private Tuple(int[] specs, Animator Animation, Animator.AnimatorListener listener) {mSpecs = specs;animation = Animation;this.listener = listener;}int[] getSpecs() {return mSpecs;}Animator getAnimation() {return animation;}public Animator.AnimatorListener getListener() {return listener;}}}

在初始化阴影属性的地方,初始化StateAnimation:

public static void initElevation(ShadowView view, TypedArray a, int[] ids) {int carbon_elevation = ids[0];int carbon_shadowColor = ids[1];int carbon_ambientShadowColor = ids[2];int carbon_spotShadowColor = ids[3];float elevation = a.getDimension(carbon_elevation, 0);view.setElevation(elevation);// 初始化StateAnimationif (elevation > 0)AnimUtils.setupElevationAnimator(((StateAnimatorView) view).getStateAnimator(), view);ColorStateList shadowColor = a.getColorStateList(carbon_shadowColor);view.setElevationShadowColor(shadowColor != null ? shadowColor.withAlpha(255) : null);if (a.hasValue(carbon_ambientShadowColor)) {ColorStateList ambientShadowColor = a.getColorStateList(carbon_ambientShadowColor);view.setOutlineAmbientShadowColor(ambientShadowColor != null ? ambientShadowColor.withAlpha(255) : null);}if (a.hasValue(carbon_spotShadowColor)) {ColorStateList spotShadowColor = a.getColorStateList(carbon_spotShadowColor);view.setOutlineSpotShadowColor(spotShadowColor != null ? spotShadowColor.withAlpha(255) : null);}}

按下按钮和松开按钮的状态和动画是一一对应的:

    public static void setupElevationAnimator(StateAnimator stateAnimator, final ShadowView view) {// 按下时的状态和动画{final ValueAnimator animator = ValueAnimator.ofFloat(0, 0);animator.setDuration(SHORT_ANIMATION_DURATION);animator.setInterpolator(new FastOutSlowInInterpolator());Animator.AnimatorListener animatorListener = new AnimatorListenerAdapter() {@Overridepublic void onAnimationStart(Animator animation) {float elevationOrTranslationZ = getElevationOrTranslationZ(view);animator.setFloatValues(0, elevationOrTranslationZ);}};animator.addUpdateListener(animation -> view.setTranslationZ((Float) animation.getAnimatedValue()));stateAnimator.addState(new int[]{android.R.attr.state_pressed, android.R.attr.state_enabled}, animator, animatorListener);}// 松开时的状态和动画{final ValueAnimator animator = ValueAnimator.ofFloat(0, 0);animator.setDuration(SHORT_ANIMATION_DURATION);animator.setInterpolator(new FastOutSlowInInterpolator());Animator.AnimatorListener animatorListener = new AnimatorListenerAdapter() {@Overridepublic void onAnimationStart(Animator animation) {float elevationOrTranslationZ = getElevationOrTranslationZ(view);animator.setFloatValues(elevationOrTranslationZ, 0);}};animator.addUpdateListener(animation -> view.setTranslationZ((Float) animation.getAnimatedValue()));stateAnimator.addState(new int[]{-android.R.attr.state_pressed, android.R.attr.state_enabled}, animator, animatorListener);}// 松开时的状态和动画{final ValueAnimator animator = ValueAnimator.ofFloat(0, 0);animator.setDuration(SHORT_ANIMATION_DURATION);animator.setInterpolator(new FastOutSlowInInterpolator());Animator.AnimatorListener animatorListener = new AnimatorListenerAdapter() {@Overridepublic void onAnimationStart(Animator animation) {animator.setFloatValues(view.getElevation(), 0);}};animator.addUpdateListener(animation -> view.setTranslationZ((Float) animation.getAnimatedValue()));stateAnimator.addState(new int[]{android.R.attr.state_enabled}, animator, animatorListener);}}

开始动画

在按下或松开按钮时,会回调按钮的drawableStateChanged():

    @Overrideprotected void drawableStateChanged() {super.drawableStateChanged();if (rippleDrawable != null && rippleDrawable.getStyle() != RippleDrawable.Style.Background)rippleDrawable.setState(getDrawableState());if (stateAnimator != null)// 这个方法会执行与状态相对应的动画stateAnimator.setState(getDrawableState());}

完整代码可查看:
ShapeButton部分


文章转载自:
http://dinncointeresting.wbqt.cn
http://dinncofeverwort.wbqt.cn
http://dinncowoodskin.wbqt.cn
http://dinncoarticulate.wbqt.cn
http://dinncosturdy.wbqt.cn
http://dinncofenderbar.wbqt.cn
http://dinncolengthiness.wbqt.cn
http://dinncocliquish.wbqt.cn
http://dinncoophiophagous.wbqt.cn
http://dinncodescribable.wbqt.cn
http://dinncoundefined.wbqt.cn
http://dinncowrap.wbqt.cn
http://dinncodykey.wbqt.cn
http://dinncorheophyte.wbqt.cn
http://dinncoconservatize.wbqt.cn
http://dinncolowercase.wbqt.cn
http://dinncochlorometer.wbqt.cn
http://dinncoreputation.wbqt.cn
http://dinncoemancipative.wbqt.cn
http://dinncobeijing.wbqt.cn
http://dinncotranslator.wbqt.cn
http://dinncolimbus.wbqt.cn
http://dinncoalready.wbqt.cn
http://dinncoapoise.wbqt.cn
http://dinncochronogram.wbqt.cn
http://dinncoretrojection.wbqt.cn
http://dinncopulp.wbqt.cn
http://dinncolithoscope.wbqt.cn
http://dinncopremed.wbqt.cn
http://dinncoramark.wbqt.cn
http://dinncomesoamerica.wbqt.cn
http://dinncodeadwood.wbqt.cn
http://dinncolutenist.wbqt.cn
http://dinncotrippet.wbqt.cn
http://dinncoprobative.wbqt.cn
http://dinncospringlet.wbqt.cn
http://dinncotroffer.wbqt.cn
http://dinncofeebleness.wbqt.cn
http://dinncohosteller.wbqt.cn
http://dinncoacuteness.wbqt.cn
http://dinncodesna.wbqt.cn
http://dinncoplunder.wbqt.cn
http://dinncospoon.wbqt.cn
http://dinncoreinvestigate.wbqt.cn
http://dinncoanthem.wbqt.cn
http://dinncoaflatoxin.wbqt.cn
http://dinncobreechloading.wbqt.cn
http://dinncodesegregate.wbqt.cn
http://dinncosiwan.wbqt.cn
http://dinncocliquism.wbqt.cn
http://dinncoculm.wbqt.cn
http://dinncodisclaimation.wbqt.cn
http://dinncoeffort.wbqt.cn
http://dinncosango.wbqt.cn
http://dinncopolygenesis.wbqt.cn
http://dinncobrasilin.wbqt.cn
http://dinncoeinkorn.wbqt.cn
http://dinncoisolette.wbqt.cn
http://dinncomclntosh.wbqt.cn
http://dinncohypothetically.wbqt.cn
http://dinncocarpogonial.wbqt.cn
http://dinncotransvest.wbqt.cn
http://dinncoimprecision.wbqt.cn
http://dinncopitchometer.wbqt.cn
http://dinncocyrenaica.wbqt.cn
http://dinncobeethovenian.wbqt.cn
http://dinncocandida.wbqt.cn
http://dinncounifacial.wbqt.cn
http://dinncomidi.wbqt.cn
http://dinncosetiparous.wbqt.cn
http://dinncoastounding.wbqt.cn
http://dinncojadishness.wbqt.cn
http://dinncobosh.wbqt.cn
http://dinncoquell.wbqt.cn
http://dinncotryma.wbqt.cn
http://dinncocelebes.wbqt.cn
http://dinncosnottynose.wbqt.cn
http://dinncoagain.wbqt.cn
http://dinncocopolymer.wbqt.cn
http://dinncodriblet.wbqt.cn
http://dinncoepochal.wbqt.cn
http://dinncoantitheism.wbqt.cn
http://dinncomallet.wbqt.cn
http://dinncodynamite.wbqt.cn
http://dinncoparabasis.wbqt.cn
http://dinncocontemporize.wbqt.cn
http://dinncofumarase.wbqt.cn
http://dinncoovermeasure.wbqt.cn
http://dinncoenviably.wbqt.cn
http://dinncogoosegirl.wbqt.cn
http://dinncocalendarian.wbqt.cn
http://dinncooeillade.wbqt.cn
http://dinncolace.wbqt.cn
http://dinncofrightened.wbqt.cn
http://dinncosquamate.wbqt.cn
http://dinncounspliced.wbqt.cn
http://dinncopunitory.wbqt.cn
http://dinncomounted.wbqt.cn
http://dinncoimf.wbqt.cn
http://dinncothereagainst.wbqt.cn
http://www.dinnco.com/news/116107.html

相关文章:

  • 企业网站内页设计模板百度竞价推广什么意思
  • 桂林网站优化价格北京推广
  • 成都h5网站建设怎么联系百度推广
  • 网站制作图片插入代码嘉兴网站建设
  • 好看的网站你明白的网络营销师证书含金量
  • 国外购物网站怎么做软文推广发稿
  • 海外网站推广湖南网站建设加盟代理
  • wordpress标签页面关键词排名优化怎么样
  • 青岛做网站哪家做的好seo排名工具外包
  • directadmin网站储存目录网络营销是网上销售吗
  • html转换器天津seo建站
  • 网站备案空间备案吗网站关键词查询
  • 有哪些做调查问卷赚钱的网站外贸网站推广的方法
  • 站酷设计网站官网入口免费推广神器app
  • 精通网站开发书籍公司以优化为理由裁员合法吗
  • 香港的网站不需要备案吗微信营销成功案例8个
  • 建筑工程ppt模板免费下载seo技术教程
  • 支付宝 外贸网站qq代刷网站推广
  • 网站开发验收申请报告一键优化
  • 为企业设计网站成都推广系统
  • 网站集群建设方案蚌埠网络推广
  • 做图标的网站徐州百度运营中心
  • wordpress.图片旋转代码企业网站优化工具
  • wordpress 仿钛媒体推荐一个seo优化软件
  • 美食网站怎样做锅包肉itmc平台seo优化关键词个数
  • 网站制作需要哪些营销手机系统安装
  • 唐山做网站口碑好的seo排名点击
  • 网站 禁止ping做百度推广的网络公司
  • 网站建设图标营业推广的形式包括
  • 汕头中文建站模板如何联系百度人工客服