本文整理汇总了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);
}
}
示例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);
}
}
示例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);
}
示例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);
}
示例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();
}
}
示例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;
}
示例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;
}
示例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;
}
示例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));
}
示例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);
}
示例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;
}
示例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);
}
}
}
示例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();
}
}
示例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);
}
}
示例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;
}