通过 ViewCompat,开发者能够使用一些在新版本中引入的方法,而不必担心应用在旧版本中的兼容性问题。...ViewCompat 的常用接口和功能 以下是一些 ViewCompat 提供的常用接口和功能,它们主要涉及视图的各种属性、动画、层级、过渡等: 1、 设置和获取视图的透明度: setAlpha(View...ViewCompat.setRotation(myView, 45f); // 设置平移 ViewCompat.setTranslationX(myView, 100f); // 设置背景色调 ColorStateList...boolean isAttached = ViewCompat.isAttachedToWindow(myView); 总结 ViewCompat 类提供了一组方法,这些方法封装了不同版本 Android...开发者通过 ViewCompat 类,能更容易地实现跨版本的视图处理,提升应用在不同 Android 版本上的兼容性与一致性。 END 点赞转发,让精彩不停歇!
This may be one of: * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or * {@link ViewCompat...This may be one of: * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or * {@link ViewCompat#LAYOUT_DIRECTION_RTL...This may be one of: * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or * {@link ViewCompat#LAYOUT_DIRECTION_RTL...This may be one of: * {@link ViewCompat#LAYOUT_DIRECTION_LTR} or * {@link ViewCompat...{@link android.support.v4.view.ViewCompat#LAYOUT_DIRECTION_RTL}
#SCROLL_AXIS_HORIZONTAL} * and/or {@link ViewCompat#SCROLL_AXIS_VERTICAL}...#SCROLL_AXIS_HORIZONTAL}, * {@link ViewCompat#SCROLL_AXIS_VERTICAL} or both...* @param type 事件类型:ViewCompat.TYPE_TOUCH和TYPE_NON_TOUCH * @return true 表示该 parent 需要处理该次嵌套滑动...#SCROLL_AXIS_HORIZONTAL}, * {@link ViewCompat#SCROLL_AXIS_VERTICAL} or both...* @param type 事件类型:ViewCompat.TYPE_TOUCH 和 TYPE_NON_TOUCH */ void onNestedScrollAccepted
= null) { ViewCompat.animate(mErrorView).cancel(); } if (enabled...(mErrorView, ViewCompat.getPaddingStart(mEditText), 0, ViewCompat.getPaddingEnd...(error); ViewCompat.animate(mErrorView) .alpha(1f)...ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (collapsedAbsGravity...ViewCompat.LAYOUT_DIRECTION_RTL : ViewCompat.LAYOUT_DIRECTION_LTR); switch (expandedAbsGravity
fling效果,ViewCompat.TYPE_TOUCH 手势滑动 */ @Override public void onNestedPreScroll(@NonNull...水平方向,垂直方向,或者不指定 * @param type 滑动类型,ViewCompat.TYPE_NON_TOUCH fling 效果ViewCompat.TYPE_TOUCH...fling 效果ViewCompat.TYPE_TOUCH 手势滑动 */ @Override public void onNestedPreScroll(@NonNull...水平方向,垂直方向,或者不指定 * @param type 滑动类型,ViewCompat.TYPE_NON_TOUCH fling 效果ViewCompat.TYPE_TOUCH...fling 效果ViewCompat.TYPE_TOUCH 手势滑动 */ @Override public void onNestedPreScroll(@NonNull
, ViewCompat.TYPE_TOUCH); break; case MotionEvent.ACTION_MOVE:...hasNestedScrollingParent(ViewCompat.TYPE_TOUCH)) { mVelocityTracker.clear();...mScrollConsumed[1] = 0; dispatchNestedPreScroll(0, unconsumed, mScrollConsumed, null, ViewCompat.TYPE_NON_TOUCH...mScroller.isFinished()) { ViewCompat.postInvalidateOnAnimation(this); } } 最后,为了确保 onTouchEvent...mScroller.isFinished(); startNestedScroll(ViewCompat.SCROLL_AXIS_VERTICAL);
transformPage(View view, float position) { //界面不可见 if (position < -1) { ViewCompat.setRotation...//界面可见 else if (position <= 1) { mRot = (ROT_MAX * position); ViewCompat.setPivotX...(view, view.getMeasuredWidth() * 0.5f); ViewCompat.setPivotY(view, view.getMeasuredHeight...()); ViewCompat.setRotation(view, mRot); } //界面不可见 else {...ViewCompat.setRotation(view, 0); } } } 测试效果 ?
(mLayout, mOverScroller.getCurrY()); ViewCompat.postOnAnimation(mLayout, this);...| ViewCompat.SCROLL_AXIS_VERTICAL); break; case...= null) { if (ViewCompat.getFitsSystemWindows(header) && !...ViewCompat.getFitsSystemWindows(child)) { // If the header is fitting system windows...(child, true); if (ViewCompat.getFitsSystemWindows(child)) {
import androidx.core.view.WindowInsetsCompat import androidx.core.view.ViewCompat fun getStatusBarHeight...(activity: Activity): Int { val insets = ViewCompat.getRootWindowInsets(activity.window.decorView...WindowInsetsCompat 进行兼容性处理: import androidx.core.view.WindowInsetsCompat import androidx.core.view.ViewCompat...fun getNavigationBarHeight(activity: Activity): Int { val insets = ViewCompat.getRootWindowInsets
#SCROLL_AXIS_HORIZONTAL}, * {@link ViewCompat#SCROLL_AXIS_VERTICAL} or both...#SCROLL_AXIS_HORIZONTAL}, * {@link ViewCompat#SCROLL_AXIS_VERTICAL} or both... * * @return Flags indicating the current axes of nested scrolling * @see ViewCompat...#SCROLL_AXIS_HORIZONTAL * @see ViewCompat#SCROLL_AXIS_VERTICAL * @see ViewCompat#SCROLL_AXIS_NONE...} * and/or {@link ViewCompat#SCROLL_AXIS_VERTICAL}
offsets mNestedOffsets[0] = mNestedOffsets[1] = 0; int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE...; if (canScrollHorizontally) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL...} if (canScrollVertically) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL...; if (canScrollHorizontally) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL...} if (canScrollVertically) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL
case MotionEvent.ACTION_DOWN: lastY = (int) event.getRawY(); startNestedScroll(ViewCompat.SCROLL_AXIS_HORIZONTAL...| ViewCompat.SCROLL_AXIS_VERTICAL);//开启嵌套滑动 break; //移动 case MotionEvent.ACTION_MOVE...0.5f); mInitialTouchY = mLastTouchY = (int) (e.getY() + 0.5f); int nestedScrollAxis = ViewCompat.SCROLL_AXIS_NONE...; if (canScrollHorizontally) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_HORIZONTAL...; } if (canScrollVertically) { nestedScrollAxis |= ViewCompat.SCROLL_AXIS_VERTICAL
mTotalDy = Math.min(mTotalDy, TARGET_HEIGHT); mLastScale = Math.max(1f, 1f + mTotalDy / TARGET_HEIGHT); ViewCompat.setScaleX...(mTargetView, mLastScale); ViewCompat.setScaleY(mTargetView, mLastScale); mLastBottom = mParentHeight...void onAnimationUpdate(ValueAnimator animation) { float value = (float) animation.getAnimatedValue(); ViewCompat.setScaleX...(mTargetView, value); ViewCompat.setScaleY(mTargetView, value); abl.setBottom((int) (mLastBottom - (mLastBottom...(mTargetView, 1f); ViewCompat.setScaleY(mTargetView, 1f); abl.setBottom(mParentHeight); middleLayout.setTop
需要注意的是,如果我们的Api版本>=14,即Android4.0及以上,则可以直接在View中实现上述方法, 否则使用 ViewCompat.setAccessibilityDelegate() 或者...而当你使用 AccessibilityDelegateCompat 时,你会发现当你调用 ViewCompat.setAccessibilityDelegate(view, null) 时,你之前的代理类就不会被调用...,是不是很离谱,而观察源码你会发现,当使用 ViewCompat设置为 null 时,内部不是直接赋值,而是给予了一个新的实例。...isCheckable = true } } ViewCompat.setAccessibilityDelegate(this, delegateCompat) 最简单的优化,我们自然可以把它提取出来...xxxViewAcesDelegate by lazyAcesDeleteSelectSimple{ //你的逻辑 true or false } val view=View(null) ViewCompat.setAccessibilityDelegate
changedView==mBottomView){ mTopView.offsetTopAndBottom(dy); } ViewCompat.postInvalidateOnAnimation...} if (mViewDragHelper.smoothSlideViewTo(releasedChild, 0, finalTop)) { ViewCompat.postInvalidateOnAnimation...public void computeScroll() { if (mViewDragHelper.continueSettling(true)) { ViewCompat.postInvalidateOnAnimation...** * 手指向下滑动(内容向上滑动) * @return */ private boolean canScrollingUp() { if (ViewCompat.canScrollVertically...* 手指向上滑动(内容向下滑动) * @return */ private boolean canScrollingDown() { if (ViewCompat.canScrollVertically
itemView) { continue; } final float elevation = ViewCompat.getElevation...= null && tag instanceof Float) { ViewCompat.setElevation(view, (Float) tag);...(view, 0f); ViewCompat.setTranslationY(view, 0f); } @Override public...view, float dX, float dY, int actionState, boolean isCurrentlyActive) { ViewCompat.setTranslationX...(view, dX); ViewCompat.setTranslationY(view, dY); } @Override public
(mView, ViewCompat.ACCESSIBILITY_LIVE_REGION_POLITE); ViewCompat.setImportantForAccessibility...(mView, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES); // Make sure that we fit...system windows and have a listener to apply any insets ViewCompat.setFitsSystemWindows(mView..., true); ViewCompat.setOnApplyWindowInsetsListener(mView, new android.support.v4...} }); } } }); if (ViewCompat.isLaidOut
start close animation"); listener.onStartCloseAnimation(); } ViewCompat.postInvalidateOnAnimation..."start open animation"); listener.onStartOpenAnimation(); } ViewCompat.postInvalidateOnAnimation...animation"); listener.onStartCloseAnimation(); } ViewCompat.postInvalidateOnAnimation...animation"); listener.onStartOpenAnimation(); } ViewCompat.postInvalidateOnAnimation...super.computeScroll(); // 开始执行动画 if (mDragHelper.continueSettling(true)) { ViewCompat.postInvalidateOnAnimation
*/ public void open() { if (mdDragHelper.smoothSlideViewTo(mainView, menuWidth, 0)) { ViewCompat.postInvalidateOnAnimation...* 关闭菜单 */ public void close() { if (mdDragHelper.smoothSlideViewTo(mainView, 0, 0)) { ViewCompat.postInvalidateOnAnimation...) { super.computeScroll(); // 开始执行动画 if (mdDragHelper.continueSettling(true)) { ViewCompat.postInvalidateOnAnimation...(this); } } 我们发现在open()和close()两个方法中都调用了ViewCompat.postInvalidateOnAnimation(this);而postInvalidateOnAnimation
领取专属 10元无门槛券
手把手带您无忧上云