Fix CustomVerticalDivider

This commit is contained in:
xynngh 2020-05-16 21:24:34 +04:00
parent ad70e3e871
commit a25aed809c
2 changed files with 7 additions and 6 deletions

View File

@ -3,6 +3,7 @@ package dummydomain.yetanothercallblocker;
import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.View;
@ -18,6 +19,8 @@ public class CustomVerticalDivider extends RecyclerView.ItemDecoration {
private Drawable mDivider;
private final Rect mBounds = new Rect();
public CustomVerticalDivider(Context context) {
final TypedArray a = context.obtainStyledAttributes(ATTRS);
mDivider = a.getDrawable(0);
@ -34,10 +37,9 @@ public class CustomVerticalDivider extends RecyclerView.ItemDecoration {
for (int i = 0; i < childCount; i++) {
View child = parent.getChildAt(i);
RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();
int top = child.getBottom() + params.bottomMargin;
int bottom = top + mDivider.getIntrinsicHeight();
parent.getDecoratedBoundsWithMargins(child, mBounds);
final int bottom = mBounds.bottom + Math.round(child.getTranslationY());
final int top = bottom - mDivider.getIntrinsicHeight();
mDivider.setBounds(left, top, right, bottom);
mDivider.draw(c);

View File

@ -13,7 +13,6 @@ import android.view.View;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.RecyclerView;
import org.greenrobot.eventbus.EventBus;
@ -52,7 +51,7 @@ public class MainActivity extends AppCompatActivity {
callLogAdapter = new CallLogItemRecyclerViewAdapter(this::onCallLogItemClicked);
recyclerView = findViewById(R.id.callLogList);
recyclerView.setAdapter(callLogAdapter);
recyclerView.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL));
recyclerView.addItemDecoration(new CustomVerticalDivider(this));
}
@Override