当前位置: 首页>>代码示例>>Java>>正文


Java ViewCompat类代码示例

本文整理汇总了Java中android.support.v4.view.ViewCompat的典型用法代码示例。如果您正苦于以下问题:Java ViewCompat类的具体用法?Java ViewCompat怎么用?Java ViewCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ViewCompat类属于android.support.v4.view包,在下文中一共展示了ViewCompat类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: translucentStatusBar

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
static void translucentStatusBar(Activity activity, boolean hideStatusBarBackground) {
    Window window = activity.getWindow();
    //添加Flag把状态栏设为可绘制模式
    window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
    if (hideStatusBarBackground) {
        //如果为全透明模式,取消设置Window半透明的Flag
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //设置状态栏为透明
        window.setStatusBarColor(Color.TRANSPARENT);
        //设置window的状态栏不可见
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    } else {
        //如果为半透明模式,添加设置Window半透明的Flag
        window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //设置系统状态栏处于可见状态
        window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
    }
    //view不根据系统窗口来调整自己的布局
    ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
    View mChildView = mContentView.getChildAt(0);
    if (mChildView != null) {
        ViewCompat.setFitsSystemWindows(mChildView, false);
        ViewCompat.requestApplyInsets(mChildView);
    }
}
 
开发者ID:bigjelly,项目名称:ShaddockVideoPlayer,代码行数:26,代码来源:EyesLollipop.java

示例2: fillChild

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
private void fillChild(View view, ItemLayoutInfo layoutInfo) {
    addView(view);
    measureChildWithExactlySize(view);
    final int scaleFix = (int) (mChildSize[mOrientation] * (1 - layoutInfo.scaleXY) / 2);
    final float gap = (mOrientation == VERTICAL ? getHorizontalSpace() : getVerticalSpace())
            - mChildSize[(mOrientation + 1) % 2] * layoutInfo.scaleXY;

    if (mOrientation == VERTICAL) {
        int left = (int) (getPaddingLeft() + (gap * 0.5 * mVanishOffset));
        layoutDecoratedWithMargins(view, left, layoutInfo.start - scaleFix
                , left + mChildSize[0], layoutInfo.start + mChildSize[1] - scaleFix);
    } else {
        int top = (int) (getPaddingTop() + (gap * 0.5 * mVanishOffset));
        layoutDecoratedWithMargins(view, layoutInfo.start - scaleFix, top
                , layoutInfo.start + mChildSize[0] - scaleFix, top + mChildSize[1]);
    }
    ViewCompat.setScaleX(view, layoutInfo.scaleXY);
    ViewCompat.setScaleY(view, layoutInfo.scaleXY);
    if (mDecorateHelper != null) {
        mDecorateHelper.decorateChild(view, layoutInfo.positionOffsetPercent, layoutInfo.layoutPercent, layoutInfo.isBottom);
    }
}
 
开发者ID:thunderpunch,项目名称:LadderLayoutManager,代码行数:23,代码来源:LadderLayoutManager.java

示例3: PullRefreshLayout

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
public PullRefreshLayout(Context context, AttributeSet attrs) {
    super(context, attrs);
    mDecelerateInterpolator = new DecelerateInterpolator(DECELERATE_INTERPOLATION_FACTOR);
    mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop();
    int defaultDuration = getResources().getInteger(android.R.integer.config_mediumAnimTime);
    mDurationToStartPosition = defaultDuration;
    mDurationToCorrectPosition = defaultDuration;
    mSpinnerFinalOffset = mTotalDragDistance = dp2px(DRAG_MAX_DISTANCE);

    mRefreshView = new ImageView(context);
    setRefreshDrawable(new PlaneDrawable(getContext(), this));
    mRefreshView.setVisibility(GONE);
    addView(mRefreshView, 0);

    mLoadView = new ImageView(context);
    setLoadDrawable(new PlaneLoadDrawable(getContext(), this));
    mLoadView.setVisibility(GONE);
    addView(mLoadView, 0);

    setWillNotDraw(false);
    ViewCompat.setChildrenDrawingOrderEnabled(this, true);
}
 
开发者ID:838030195,项目名称:DaiGo,代码行数:23,代码来源:PullRefreshLayout.java

示例4: BGASwipeBackLayout2

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
public BGASwipeBackLayout2(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);

        final float density = context.getResources().getDisplayMetrics().density;

        // ======================== 新加的 START ========================
//        mOverhangSize = (int) (DEFAULT_OVERHANG_SIZE * density + 0.5f);
        mOverhangSize = 0;
        // ======================== 新加的 END ========================

        final ViewConfiguration viewConfig = ViewConfiguration.get(context);

        setWillNotDraw(false);

        ViewCompat.setAccessibilityDelegate(this, new AccessibilityDelegate());
        ViewCompat.setImportantForAccessibility(this, ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);

        mDragHelper = ViewDragHelper.create(this, 0.5f, new DragHelperCallback());
        mDragHelper.setMinVelocity(MIN_FLING_VELOCITY * density);
    }
 
开发者ID:zhudongya123,项目名称:WechatChatroomHelper,代码行数:21,代码来源:BGASwipeBackLayout2.java

示例5: slideTo

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
private void slideTo(int slideOffset, boolean forceInstant) {
  if (animator != null) {
    animator.cancel();
    animator = null;
  }

  if (!forceInstant) {
    animator = ObjectAnimator.ofInt(this, "slideOffset", this.slideOffset, slideOffset);
    animator.setInterpolator(new FastOutSlowInInterpolator());
    animator.setDuration(400);
    animator.start();
    ViewCompat.postInvalidateOnAnimation(this);
  } else {
    this.slideOffset = slideOffset;
    requestLayout();
    invalidate();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:19,代码来源:QuickAttachmentDrawer.java

示例6: onStartNestedScroll

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
@Override
    public boolean onStartNestedScroll(CoordinatorLayout parent, AppBarLayout child,
            View directTargetChild, View target, int nestedScrollAxes, int type) {
  // Return true if we're nested scrolling vertically, and we have scrollable children
  // and the scrolling view is big enough to scroll
        final boolean started = (nestedScrollAxes & ViewCompat.SCROLL_AXIS_VERTICAL) != 0
          && child.hasScrollableChildren()
          && parent.getHeight() - directTargetChild.getHeight() <= child.getHeight();

  if (started && mOffsetAnimator != null) {
    // Cancel any offset animation
    mOffsetAnimator.cancel();
  }

  // A new nested scroll has started so clear out the previous ref
  mLastNestedScrollingChildRef = null;

  return started;
}
 
开发者ID:commonsguy,项目名称:cwac-crossport,代码行数:20,代码来源:AppBarLayout.java

示例7: endChangeAnimationIfNecessary

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
private boolean endChangeAnimationIfNecessary(ChangeInfo changeInfo, RecyclerView.ViewHolder item) {
    boolean oldItem = false;
    if (changeInfo.newHolder == item) {
        changeInfo.newHolder = null;
    } else if (changeInfo.oldHolder == item) {
        changeInfo.oldHolder = null;
        oldItem = true;
    } else {
        return false;
    }
    ViewCompat.setAlpha(item.itemView, 1);
    ViewCompat.setTranslationX(item.itemView, 0);
    ViewCompat.setTranslationY(item.itemView, 0);
    dispatchChangeFinished(item, oldItem);
    return true;
}
 
开发者ID:qsyj,项目名称:ShortcutMenu,代码行数:17,代码来源:ShortMenuAnimator.java

示例8: onLongClick

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
public boolean onLongClick(View v) {
    if (hasText()) {
        return false;
    }
    int[] screenPos = new int[2];
    Rect displayFrame = new Rect();
    getLocationOnScreen(screenPos);
    getWindowVisibleDisplayFrame(displayFrame);
    Context context = getContext();
    int width = getWidth();
    int height = getHeight();
    int midy = screenPos[1] + (height / 2);
    int referenceX = screenPos[0] + (width / 2);
    if (ViewCompat.getLayoutDirection(v) == 0) {
        referenceX = context.getResources().getDisplayMetrics().widthPixels - referenceX;
    }
    Toast cheatSheet = Toast.makeText(context, this.mItemData.getTitle(), 0);
    if (midy < displayFrame.height()) {
        cheatSheet.setGravity(8388661, referenceX, (screenPos[1] + height) - displayFrame.top);
    } else {
        cheatSheet.setGravity(81, 0, height);
    }
    cheatSheet.show();
    return true;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:26,代码来源:ActionMenuItemView.java

示例9: canScroll

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
/**
 * Tests scrollability within child views of v given a delta of dx.
 *
 * @param v View to test for horizontal scrollability
 * @param checkV Whether the view v passed should itself be checked for scrollability (true),
 *               or just its children (false).
 * @param dx Delta scrolled in pixels along the X axis
 * @param dy Delta scrolled in pixels along the Y axis
 * @param x X coordinate of the active touch point
 * @param y Y coordinate of the active touch point
 * @return true if child views of v can be scrolled by delta of dx.
 */
protected boolean canScroll(View v, boolean checkV, int dx, int dy, int x, int y) {
    if (v instanceof ViewGroup) {
        final ViewGroup group = (ViewGroup) v;
        final int scrollX = v.getScrollX();
        final int scrollY = v.getScrollY();
        final int count = group.getChildCount();
        // Count backwards - let topmost views consume scroll distance first.
        for (int i = count - 1; i >= 0; i--) {
            // TODO: Add versioned support here for transformed views.
            // This will not work for transformed views in Honeycomb+
            final View child = group.getChildAt(i);
            if (x + scrollX >= child.getLeft() && x + scrollX < child.getRight() &&
                    y + scrollY >= child.getTop() && y + scrollY < child.getBottom() &&
                    canScroll(child, true, dx, dy, x + scrollX - child.getLeft(),
                            y + scrollY - child.getTop())) {
                return true;
            }
        }
    }

    return checkV && (ViewCompat.canScrollHorizontally(v, -dx) ||
            ViewCompat.canScrollVertically(v, -dy));
}
 
开发者ID:eventtus,项目名称:photo-editor-android,代码行数:36,代码来源:ViewDragHelper.java

示例10: NestedScrollView

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
public NestedScrollView(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    this.mTempRect = new Rect();
    this.mIsLayoutDirty = true;
    this.mIsLaidOut = false;
    this.mChildToScrollTo = null;
    this.mIsBeingDragged = false;
    this.mSmoothScrollingEnabled = true;
    this.mActivePointerId = -1;
    this.mScrollOffset = new int[2];
    this.mScrollConsumed = new int[2];
    initScrollView();
    TypedArray a = context.obtainStyledAttributes(attrs, SCROLLVIEW_STYLEABLE, defStyleAttr, 0);
    setFillViewport(a.getBoolean(0, false));
    a.recycle();
    this.mParentHelper = new NestedScrollingParentHelper(this);
    this.mChildHelper = new NestedScrollingChildHelper(this);
    setNestedScrollingEnabled(true);
    ViewCompat.setAccessibilityDelegate(this, ACCESSIBILITY_DELEGATE);
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:21,代码来源:NestedScrollView.java

示例11: getFabTranslationYForBottomNavigationBar

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
private float[] getFabTranslationYForBottomNavigationBar(CoordinatorLayout parent,
                                                         FloatingActionButton fab) {
    float minOffset = 0;
    float viewHeight = 0;
    final List<View> dependencies = parent.getDependencies(fab);
    for (int i = 0, z = dependencies.size(); i < z; i++) {
        final View view = dependencies.get(i);
        if (view instanceof BottomNavigationBar) {
            viewHeight = view.getHeight();
            minOffset = Math.min(minOffset,
                    ViewCompat.getTranslationY(view) - viewHeight);
        }
    }
    float[] returnValues = {minOffset, viewHeight};

    return returnValues;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:18,代码来源:BottomNavBarFabBehaviour.java

示例12: updateChildrenImportantForAccessibility

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
private void updateChildrenImportantForAccessibility(View drawerView, boolean isDrawerOpen) {
  final int childCount = getChildCount();
  for (int i = 0; i < childCount; i++) {
    final View child = getChildAt(i);
    if (!isDrawerOpen && !isDrawerView(child)
        || isDrawerOpen && child == drawerView) {
      // Drawer is closed and this is a content view or this is an
      // open drawer view, so it should be visible.
      ViewCompat.setImportantForAccessibility(child,
          ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_YES);
    } else {
      ViewCompat.setImportantForAccessibility(child,
          ViewCompat.IMPORTANT_FOR_ACCESSIBILITY_NO_HIDE_DESCENDANTS);
    }
  }
}
 
开发者ID:rogues-dev,项目名称:superglue,代码行数:17,代码来源:DebugDrawerLayout.java

示例13: onDestroy

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
@Override
public void onDestroy() {
    super.onDestroy();
    mItems.clear();
    mRecyclerViewAdapter = null;
    setAppBarLayoutAlpha(255);
    if (mAppBarLayout != null && !isForeground()) {
        mAppBarLayout.setTranslationY(0);
        ViewCompat.setElevation(mAppBarLayout, 0);
    }
    if (mLoader != null) {
        mLoader.cancel(true);
        mLoader = null;
    }
    if (mHandler != null) {
        mHandler.removeCallbacks(mRefresh);
    }
    mAdView = null;
    for (RecyclerViewItem item : mItems) {
        item.onDestroy();
    }
}
 
开发者ID:AyushR1,项目名称:KernelAdiutor-Mod,代码行数:23,代码来源:RecyclerViewFragment.java

示例14: canChildScrollUp

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
/**
 * Whether child view can scroll up
 * @return
 */
public boolean canChildScrollUp() {
  if (mTargetView == null) {
    return false;
  }
  if (Build.VERSION.SDK_INT < 14) {
    if (mTargetView instanceof AbsListView) {
      final AbsListView absListView = (AbsListView) mTargetView;
      return absListView.getChildCount() > 0
             && (absListView.getFirstVisiblePosition() > 0 || absListView.getChildAt(0)
                                                                  .getTop() < absListView.getPaddingTop());
    } else {
      return ViewCompat.canScrollVertically(mTargetView, -1) || mTargetView.getScrollY() > 0;
    }
  } else {
    return ViewCompat.canScrollVertically(mTargetView, -1);
  }
}
 
开发者ID:amap-demo,项目名称:weex-3d-map,代码行数:22,代码来源:WXSwipeLayout.java

示例15: animateChange

import android.support.v4.view.ViewCompat; //导入依赖的package包/类
public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromX, int fromY, int toX, int toY) {
    if (oldHolder == newHolder) {
        return animateMove(oldHolder, fromX, fromY, toX, toY);
    }
    float prevTranslationX = ViewCompat.getTranslationX(oldHolder.itemView);
    float prevTranslationY = ViewCompat.getTranslationY(oldHolder.itemView);
    float prevAlpha = ViewCompat.getAlpha(oldHolder.itemView);
    resetAnimation(oldHolder);
    int deltaX = (int) (((float) (toX - fromX)) - prevTranslationX);
    int deltaY = (int) (((float) (toY - fromY)) - prevTranslationY);
    ViewCompat.setTranslationX(oldHolder.itemView, prevTranslationX);
    ViewCompat.setTranslationY(oldHolder.itemView, prevTranslationY);
    ViewCompat.setAlpha(oldHolder.itemView, prevAlpha);
    if (newHolder != null) {
        resetAnimation(newHolder);
        ViewCompat.setTranslationX(newHolder.itemView, (float) (-deltaX));
        ViewCompat.setTranslationY(newHolder.itemView, (float) (-deltaY));
        ViewCompat.setAlpha(newHolder.itemView, 0.0f);
    }
    this.mPendingChanges.add(new ChangeInfo(oldHolder, newHolder, fromX, fromY, toX, toY));
    return true;
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:23,代码来源:DefaultItemAnimator.java


注:本文中的android.support.v4.view.ViewCompat类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。