logo
Tags down

shadow

RecyclerView with CardView Items, notifyItemChanged and shadow problem


By : sri krishna
Date : October 16 2020, 06:10 AM
Does that help Set a constraint layout inside cardView, then you can clearly see the shadow:-
code :
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="6dp"
    tools:context=".MainActivity">

    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent">
    </android.support.constraint.ConstraintLayout>

</android.support.v7.widget.CardView>


Share : facebook icon twitter icon

notifyItemChanged(int position) updates multiple items in RecyclerView


By : Vortex-5
Date : March 29 2020, 07:55 AM
will be helpful for those in need The problem is in your onBindViewHolder() where you didn't use else case for if statement. It shoult be like:
code :
public void onBindViewHolder(final ViewHolder holder, final int position) {
        MyObj myObj = myList.get(position);
        boolean isSpecial = myObj.getMySpecialStatus();

        holder.myItemTitle.setText(myObj.getTitle());

        //decide if item has different icon state
        if (isSpecial) {
            holder.myItemIcon.setImageResource(R.drawable.ic_special);    

         } else {
            //here is the trick - set normal state back
            holder.myItemIcon.setImageResource(R.drawable.ic_standard);
         }
    }

Android CardView inside RecyclerView - cardElevation cause unwanted margin & bottom shadow


By : wisdom
Date : March 29 2020, 07:55 AM
fixed the issue. Will look into that further My raw guess is, you are using CardView from support library. There are different card view implementation under different version of of Android.
I believe before Android L, the library add padding in order to reserve space for shadow drawing.

cardview shadow elevation animation in recyclerview


By : User 001
Date : March 29 2020, 07:55 AM
this will help How to do it? Using Viewpager and Shadow Transform
1- create a PagerAdapter for cardview
code :
 CardView cardView = (CardView) view.findViewById(R.id.cardView);

        if (mBaseElevation == 0) {
            mBaseElevation = cardView.getCardElevation();
        }

        cardView.setMaxCardElevation(mBaseElevation * MAX_ELEVATION_FACTOR);
        mViews.set(position, cardView);
        return view;
        if (currentCard != null) {
            if (mScalingEnabled) {
                currentCard.setScaleX((float) (1 + 0.1 * (1 - realOffset)));
                currentCard.setScaleY((float) (1 + 0.1 * (1 - realOffset)));
            }
            currentCard.setCardElevation((baseElevation + baseElevation
                    * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (1 - realOffset)));
        }

        CardView nextCard = mAdapter.getCardViewAt(nextPosition);

        // We might be scrolling fast enough so that the next (or previous) card
        // was already destroyed or a fragment might not have been created yet
        if (nextCard != null) {
            if (mScalingEnabled) {
                nextCard.setScaleX((float) (1 + 0.1 * (realOffset)));
                nextCard.setScaleY((float) (1 + 0.1 * (realOffset)));
            }
            nextCard.setCardElevation((baseElevation + baseElevation
                    * (CardAdapter.MAX_ELEVATION_FACTOR - 1) * (realOffset)));
        }

How to make RecyclerView inside CardView and CardView have it's size when it has low items


By : xfashion
Date : March 29 2020, 07:55 AM
will help you At first you can solve by changing your relativelayout inside CardView to LinearLayout and create nested relativelayouts for buttons. In order to avoid the nested layouts try my below code will help you..
code :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_margin="12dp"
    app:cardElevation="8dp">

        <TextView
            android:id="@+id/activeInspections"
            android:layout_width="match_parent"
            android:layout_height="25dp"
            android:text=" Your active inspections"
            android:textSize="18sp" />

        <android.support.v7.widget.RecyclerView
            android:id="@+id/rvActiveInspections"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="60dp"
            android:layout_marginTop="25dp" />


        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:id="@+id/btnClear"
            android:layout_gravity="bottom"
            android:background="?selectableItemBackground"
            android:text="CLear" />

        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginBottom="8dp"
            android:layout_marginTop="8dp"
            android:id="@+id/btnContinue"
            android:layout_gravity="bottom|end"
            android:background="?selectableItemBackground"
            android:text="Continue"
            android:textColor="@color/bb_darkBackgroundColor" />


</android.support.v7.widget.CardView>

</LinearLayout>

How can I draw a CardView shadow to a canvas in a RecyclerView ItemDecoration?


By : Indivibe Updates
Date : March 29 2020, 07:55 AM
To fix this issue This is card view decoration example. This is my reference: https://github.com/bleeding182/recyclerviewItemDecorations
code :
Paint mPaint;

static RoundRectHelper sRoundRectHelper;

Paint mCornerShadowPaint;

Paint mEdgeShadowPaint;

final RectF mPreShadowBounds;

float mCornerRadius;

Path mCornerShadowPath;

float mShadowSize;

private boolean mDirty = true;

private final int mShadowStartColor;

private final int mShadowEndColor;
private float mPadding;


public CardViewDecoration(Resources resources, int backgroundColor, float radius) {
    mShadowStartColor = resources.getColor(R.color.cardview_shadow_start_color);
    mShadowEndColor = resources.getColor(R.color.cardview_shadow_end_color);
    mShadowSize = resources.getDimension(R.dimen.cardview_shadow_size) * SHADOW_MULTIPLIER;

    mPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mPaint.setColor(backgroundColor);
    mCornerShadowPaint = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
    mCornerShadowPaint.setStyle(Paint.Style.FILL);
    mCornerShadowPaint.setDither(true);
    mCornerRadius = radius;
    mPreShadowBounds = new RectF();
    mEdgeShadowPaint = new Paint(mCornerShadowPaint);

    buildShadowCorners();
}

@Override
public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
    Rect bounds = new Rect();
    float edgeShadowTop = -mCornerRadius - mShadowSize;

    RecyclerView.LayoutManager lm = parent.getLayoutManager();
    float size16dp = 16f;
    int padding16dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size16dp, parent.getContext().getResources().getDisplayMetrics());

    for (int i = 0; i < parent.getChildCount(); i++) {
        int save = c.save();

        // using decorated values, remove what we set before
        View child = parent.getChildAt(i);
        bounds.set(lm.getDecoratedLeft(child) + padding16dp - (int) mPadding,
                lm.getDecoratedTop(child),
                lm.getDecoratedRight(child) - padding16dp + (int) mPadding,
                lm.getDecoratedBottom(child));

        RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
        int position = params.getViewAdapterPosition();
        int viewType = parent.getAdapter().getItemViewType(position);


        if (viewType == HeaderItemTestAdapter.HEADER) {
            bounds.top = (int) (bounds.top + padding16dp - mPadding);

            // LT
            c.translate(bounds.left + mCornerRadius, bounds.top + mCornerRadius);
            c.drawPath(mCornerShadowPath, mCornerShadowPaint);
            c.drawRect(0, edgeShadowTop, bounds.width() - 2 * mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

            // RT
            c.rotate(90f);
            c.translate(0, -bounds.width() + 2 * mCornerRadius);
            c.drawPath(mCornerShadowPath, mCornerShadowPaint);
            c.drawRect(0, edgeShadowTop, bounds.height() - mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

            // LBorder
            c.rotate(180f);
            c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
            c.drawRect(mCornerRadius, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);


        } else {
            if (parent.getAdapter().getItemViewType(position + 1) == HeaderItemTestAdapter.HEADER) {
                bounds.bottom = (int) (bounds.bottom - padding16dp + mPadding);

                // last item before next header
                c.rotate(180f);
                c.translate(-bounds.left - bounds.width() + mCornerRadius, -bounds.top - bounds.height() + mCornerRadius);

                c.drawPath(mCornerShadowPath, mCornerShadowPaint);
                c.drawRect(0, edgeShadowTop, bounds.width() - 2 * mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

                // RT / Right border
                c.rotate(90f);
                c.translate(0, -bounds.width() + 2 * mCornerRadius);
                c.drawPath(mCornerShadowPath, mCornerShadowPaint);
                c.drawRect(0, edgeShadowTop, bounds.height() - mCornerRadius, -mCornerRadius, mEdgeShadowPaint);

                // Left border
                c.rotate(180f);
                c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
                c.drawRect(mCornerRadius, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);
            } else {
                // Right border
                c.translate(bounds.left, bounds.top);
                c.rotate(90f);
                c.translate(0, -bounds.width() + mCornerRadius);
                c.drawRect(0, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);

                // Left border
                c.rotate(180f);
                c.translate(-bounds.height(), -bounds.width() + 2 * mCornerRadius);
                c.drawRect(0, edgeShadowTop, bounds.height(), -mCornerRadius, mEdgeShadowPaint);
            }
        }
        c.restoreToCount(save);
    }
}

private void buildShadowCorners() {

    mPadding = 0f;

    RectF innerBounds = new RectF(-mCornerRadius, -mCornerRadius, mCornerRadius, mCornerRadius);
    RectF outerBounds = new RectF(innerBounds);
    outerBounds.inset(-mShadowSize, -mShadowSize);

    if (mCornerShadowPath == null) {
        mCornerShadowPath = new Path();
    } else {
        mCornerShadowPath.reset();
    }
    mCornerShadowPath.setFillType(Path.FillType.EVEN_ODD);
    mCornerShadowPath.moveTo(-mCornerRadius, 0);
    mCornerShadowPath.rLineTo(-mShadowSize, 0);
    // outer arc
    mCornerShadowPath.arcTo(outerBounds, 180f, 90f, false);
    // inner arc
    mCornerShadowPath.arcTo(innerBounds, 270f, -90f, false);
    mCornerShadowPath.close();

    float startRatio = mCornerRadius / (mCornerRadius + mShadowSize);
    mCornerShadowPaint.setShader(new RadialGradient(0, 0, mCornerRadius + mShadowSize, new int[]{
            mShadowStartColor, mShadowStartColor, mShadowEndColor}, new float[]{0f, startRatio, 1f},
            Shader.TileMode.CLAMP));

    // we offset the content shadowSize/2 pixels up to make it more realistic.
    // this is why edge shadow shader has some extra space
    // When drawing bottom edge shadow, we use that extra space.
    mEdgeShadowPaint.setShader(new LinearGradient(0, -mCornerRadius + mShadowSize, 0, -mCornerRadius - mShadowSize,
            new int[]{mShadowStartColor, mShadowStartColor, mShadowEndColor}, new float[]{0f, .5f, 1f},
            Shader.TileMode.CLAMP));
}

@Override
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
    super.getItemOffsets(outRect, view, parent, state);
    Resources resources = parent.getContext().getResources();

    float size16dp = 16f;
    int padding16dp = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, size16dp, resources.getDisplayMetrics());

    RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) view.getLayoutParams();
    int position = params.getViewAdapterPosition();
    int viewType = parent.getAdapter().getItemViewType(position);

    if (viewType == HeaderItemTestAdapter.HEADER) {
        // header
        outRect.set(0, (int) (padding16dp), 0, 0);
    } else {
        if (parent.getAdapter().getItemViewType(position + 1) == HeaderItemTestAdapter.HEADER) {
            // last item before next header
            outRect.set(0, 0, 0, (int) (padding16dp));
        }
    }

    outRect.left = (int) padding16dp;
    outRect.right = (int) padding16dp;
}
}
Related Posts Related Posts :
  • How to apply multiple generics in a function using Kotlin
  • Gradle DSL method not found: 'kapt()'
  • Android ADB: How to push multiple files, into an emulator?
  • How to run a multiple AND query with Android Room?
  • How do i fix the getting null location value from FusedLocationProviderClient in android
  • Which ad formats uses tinder?
  • How to perform delete api in retrofit
  • AWS AppSync Error - AWSMobileClientStore.get(String) on null object reference
  • How to make back button on WebView work in onBackPressed?
  • Circular reference error in firebase with R8
  • how can I move views on the right direction in constrainlayout
  • Send Intent From Activity To Fragment
  • findViewById with PhotoView library problem
  • Removing the bottom Padding from a TextView while using HTML Format
  • Defining resValue conditionally in build.gradle
  • Is there another solutions instead of nested Recyclerview
  • Firebase + Flutter - Cloud functions onCall result in "unauthenticated" error from Android app
  • How to change textview text on cardview click?
  • App crash on opening document for some devices
  • How to fix Android compatibility warnings
  • Can't override android color resources
  • How add menu item's only for debug build type
  • Start activity without click on push notification's item
  • Checking if kapt uses incremental annotation processing
  • Show locations near user's location
  • How to hide a sub-mesh from SFB file in ArCore Android
  • There is always a default background on TextInputLayout in Android
  • 'List' is abstract; cannot be instantiated
  • A list in a list?
  • Wrong date returned from Location.getTime after 6 April 2019 (week number rollover)
  • socket connection using retrofit in Kotlin
  • Build Command Failed for CMake
  • Navigating between pages
  • Android : Support in-app updates result getting cancelled
  • What will cause Modifier 'abstract' not allowed here in RoomDatabase file using Android Studio?
  • Layout Expression - Ternary Operation for drawable value
  • How to have an Android Button with only a bottom border?
  • Actions on Google - Unable to test intent for app action on Android
  • Required single selection on MaterialButtonToggleGroup
  • AAPT: error: attribute android:forceDarkAllowed not found
  • Stop reloading previous fragment by using Navigation architecure
  • How to close the SimpleDialog in flutter after choosing an option
  • Sniffing SSL packets using Wireshark
  • Integrating google map api key in my android project
  • How to fix TextView position when text in it changes
  • Prevent 3rd party libraries to get my push notifications
  • Android bluetooth printer app works fine in debug mode but doesn't work in release mode
  • Unable To Get Particular Data From SQlite Database
  • Gradle + Cmake add unexpected Quotation marks when concatenate path
  • How to perform collection group query using document ID in Cloud Firestore
  • Navigating to a different activity using Kotlin
  • StorageException while uploading image to Firebase
  • Android WebView Has started crashing on Android 9
  • How do I create a spinner with custom id values?
  • How does CameraX library can turn ON/OFF the torch?
  • Getting Lat/Long in center of the map in Mapview
  • button click save sharedPreferences
  • ERROR: Failed to resolve: Toasty Affected Modules: app
  • How to get last text when a user paste it in the edittext
  • How to update apk in google play console after rejection application?
  • shadow
    Privacy Policy - Terms - Contact Us © 35dp-dentalpractice.co.uk