if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) { try { setOutlineProvider(getOutlineProvider());
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = getMeasuredWidth(); height = getMeasuredHeight(); mClipPath = PathProvider.getClipPath(width, height, curvatureHeight, curvatureDirection, gravity); ViewCompat.setElevation(this, ViewCompat.getElevation(this)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { Log.d(TAG, e.getMessage()); } } }
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); width = getMeasuredWidth(); height = getMeasuredHeight(); mClipPath = PathProvider.getClipPath(width, height, curvatureHeight, 0, 0); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { ViewCompat.setElevation(this, ViewCompat.getElevation(this)); } if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { try { setOutlineProvider(getOutlineProvider()); } catch (Exception e) { Log.d(TAG, e.getMessage()); } } }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && ViewCompat.getElevation(this) > 0f) { try { setOutlineProvider(getOutlineProvider());
private float findMaxElevation(RecyclerView recyclerView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; } }
private float findMaxElevation(RecyclerView recyclerView, View itemView) { final int childCount = recyclerView.getChildCount(); float max = 0; for (int i = 0; i < childCount; i++) { final View child = recyclerView.getChildAt(i); if (child == itemView) { continue; } final float elevation = ViewCompat.getElevation(child); if (elevation > max) { max = elevation; } } return max; }
/** * Finds the elevation of the highest visible viewHolder to make sure the elevated view * from {@link #updateElevation(RecyclerView, RecyclerView.ViewHolder, boolean)} is above * all others. * * @param recyclerView The RecyclerView to use when determining the height of all the visible ViewHolders */ protected float findMaxElevation(@NonNull RecyclerView recyclerView) { float maxChildElevation = 0; for (int i = 0; i < recyclerView.getChildCount(); i++) { View child = recyclerView.getChildAt(i); float elevation = ViewCompat.getElevation(child); if (elevation > maxChildElevation) { maxChildElevation = elevation; } } return maxChildElevation; } }
private void checkbox(boolean visible) { if(visible) { checkbox.setVisibility(View.VISIBLE); checkbox.bringToFront(); ViewCompat.setElevation(checkbox, ViewCompat.getElevation(child) + 1); } else { checkbox.setVisibility(View.GONE); } }
public void init(Context context, AttributeSet attrs) { mContext = context; porterDuffXfermode = new PorterDuffXfermode(PorterDuff.Mode.CLEAR); mPath = new Path(); mOutlinePath = new Path(); mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); TypedArray styledAttributes = getContext().obtainStyledAttributes(attrs, R.styleable.DiagonalView, 0, 0); angle = styledAttributes.getInt(R.styleable.DiagonalView_angle, 0); if (styledAttributes.hasValue(R.styleable.DiagonalView_diagonalGravity)) { diagonalGravity = styledAttributes.getInt(R.styleable.DiagonalView_diagonalGravity, 0); } if (styledAttributes.hasValue(R.styleable.DiagonalView_horizontalShift)) { shift = (int) styledAttributes.getDimension(R.styleable.DiagonalView_horizontalShift, 0); } styledAttributes.recycle(); ViewCompat.setElevation(this, ViewCompat.getElevation(this)); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { setOutlineProvider(getOutlineProvider()); } }
/** * Updates the elevation for the specified <code>holder</code> by either increasing * or decreasing by the specified amount * * @param recyclerView The recyclerView to use when calculating the new elevation * @param holder The ViewHolder to increase or decrease the elevation for * @param elevate True if the <code>holder</code> should have it's elevation increased */ protected void updateElevation(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder holder, boolean elevate) { if (elevate) { originalElevation = ViewCompat.getElevation(holder.itemView); float newElevation = activeElevationChange + findMaxElevation(recyclerView); ViewCompat.setElevation(holder.itemView, newElevation); isElevated = true; } else { ViewCompat.setElevation(holder.itemView, originalElevation); originalElevation = 0; isElevated = false; } }
public void init(Context context, AttributeSet attrs) { settings = new ArcViewSettings(context, attrs); settings.setElevation(ViewCompat.getElevation(this)); /** * If hardware acceleration is on (default from API 14), clipPath worked correctly * from API 18. * * So we will disable hardware Acceleration if API < 18 * * https://developer.android.com/guide/topics/graphics/hardware-accel.html#unsupported * Section #Unsupported Drawing Operations */ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN_MR2) { setLayerType(View.LAYER_TYPE_SOFTWARE, null); } setBackgroundColor(Color.TRANSPARENT); setInsetsColor(Color.TRANSPARENT); THRESHOLD = Math.round(ArcViewSettings.dpToPx(getContext(), 15)); //some threshold for child views while remeasuring them }
public void setupWithTabLayout(final TabLayout tableLayout){ mTabLayout = tableLayout; tableLayout.setSelectedTabIndicatorColor(Color.TRANSPARENT); tableLayout.setOnTabSelectedListener(this); tableLayout.getViewTreeObserver().addOnScrollChangedListener(new ViewTreeObserver.OnScrollChangedListener() { @Override public void onScrollChanged() { if (mTabLayout.getScrollX() != getScrollX()) scrollTo(mTabLayout.getScrollX(), mTabLayout.getScrollY()); } }); ViewCompat.setElevation(this, ViewCompat.getElevation(mTabLayout)); tableLayout.post(new Runnable() { @Override public void run() { if (mTabLayout.getTabCount() > 0) onTabSelected(mTabLayout.getTabAt(0)); } }); //清除Tab background for(int tab = 0; tab < tableLayout.getTabCount() ; tab++){ View tabView = getTabViewByPosition(tab); tabView.setBackgroundResource(0); } }