private void initiateDimens() { PtrLocalDisplay.init(mContext); // 拖动总距离 mTotalDragDistance = PtrLocalDisplay.dp2px(120); // 屏幕宽度 mScreenWidth = getContext().getResources().getDisplayMetrics().widthPixels; // 0.65 * 屏幕宽度 mSkyHeight = (int) (SKY_RATIO * mScreenWidth); // 天空向上偏移量 mSkyTopOffset = -(mSkyHeight * 0.28f); // 移动偏移量 mSkyMoveOffset = PtrLocalDisplay.designedDP2px(15); // 0.22 * 屏幕宽度 mTownHeight = (int) (TOWN_RATIO * mScreenWidth); // 初始偏移 mTownInitialTopOffset = (mTotalDragDistance - mTownHeight * TOWN_INITIAL_SCALE) + mTotalDragDistance * .42f; mTownFinalTopOffset = (mTotalDragDistance - mTownHeight * TOWN_FINAL_SCALE) + mTotalDragDistance * .42f; // 建筑移动偏移 mTownMoveOffset = PtrLocalDisplay.designedDP2px(10); mSunLeftOffset = 0.3f * (float) mScreenWidth; mSunTopOffset = (mTotalDragDistance * 0.5f); mTop = 0; }
@SuppressLint("NewApi") private void setUp(final double diameter) { PtrLocalDisplay.init(mParent.getContext()); final int shadowYOffset = PtrLocalDisplay.dp2px(Y_OFFSET); final int shadowXOffset = PtrLocalDisplay.dp2px(X_OFFSET); int mShadowRadius = PtrLocalDisplay.dp2px(SHADOW_RADIUS); OvalShape oval = new OvalShadow(mShadowRadius, (int) diameter); mShadow = new ShapeDrawable(oval); if (Build.VERSION.SDK_INT >= 11) { mParent.setLayerType(View.LAYER_TYPE_SOFTWARE, mShadow.getPaint()); } mShadow .getPaint() .setShadowLayer(mShadowRadius, shadowXOffset, shadowYOffset, KEY_SHADOW_COLOR); }