0

I am using a dialog and in this dialog I am using a recyclerview and I am also setting a custom background drawable with rounded corners for that dialog. the problem is whenever I try to set an item decoration for the recyclerview it shows some weird lines in bottom cut corners of dialog like here 1 and here 2 I think that's because I set the dialog background to be transparent. I want to know how to remove these lines

The item decoration

public ItemDecoration(Context context) {

        mDivider = context.getResources().getDrawable(R.drawable.recycler_horizontal_divider);
    }

    @Override
    public void onDrawOver(Canvas c, RecyclerView parent, RecyclerView.State state) {
        int left = parent.getPaddingLeft();
        int right = parent.getWidth() - parent.getPaddingRight();

        int childCount = parent.getChildCount();
        for (int i = 0; i <= childCount-2; i++) {
            View child = parent.getChildAt(i);

            RecyclerView.LayoutParams params = (RecyclerView.LayoutParams) child.getLayoutParams();

            int top = child.getBottom() + params.bottomMargin;
            int bottom = top + mDivider.getIntrinsicHeight();

            mDivider.setBounds(left, top, right, bottom);
            mDivider.draw(c);
        }
    }

the background for dialog

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"></solid>
    <corners android:radius="@dimen/viewsRadius"></corners>
</shape>

Layout for dialog

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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="wrap_content"
    android:background="@drawable/rounded_corners_dialog_back"
    >


    <TextView
        android:id="@+id/dialogNameTxt"
        android:layout_width="wrap_content"
        android:layout_height="30dp"
        android:layout_alignParentStart="true"
        android:layout_marginStart="10dp"
        android:layout_marginTop="10dp"
        android:gravity="center"
        android:tag="bold"
        android:text=""
        android:textColor="@color/black"
        android:textSize="@dimen/textSize"
        android:textStyle="" />

    <TextView
        android:id="@+id/closeBtn"
        android:layout_width="30dp"
        android:layout_height="30dp"
        android:layout_alignParentEnd="true"
        android:layout_marginTop="10dp"
        android:layout_marginEnd="10dp"
        android:tag="icon"
        android:gravity="center"
        android:background="@drawable/yellow_circle"
        android:textColor="@color/white"
        android:textSize="@dimen/textSize"
        android:text="@string/closeIcon" />

    <android.support.v7.widget.RecyclerView
        android:id="@+id/dialogList"
        android:layout_width="match_parent"
        android:layout_height="200dp"
        android:layout_below="@id/closeBtn"
        android:tag="bold" />

    <Button
        android:id="@+id/addBtn"
        android:layout_width="match_parent"
        android:layout_height="@dimen/viewsHeight"
        android:text="@string/add"
        android:tag="bold"
        android:layout_margin="10dp"
        android:textColor="@color/white"
        android:textAllCaps="false"
        android:background="@drawable/rounded_yellow_button"
        android:layout_below="@id/dialogList"
        />

  <android.support.constraint.ConstraintLayout
      android:visibility="gone"
      android:id="@+id/commentView"
      android:layout_width="match_parent"
      android:layout_below="@id/dialogList"
     android:layout_margin="10dp"
      android:layout_height="wrap_content">

      <EditText
          android:id="@+id/messageEditTxt"
          android:layout_width="0dp"
          android:layout_height="@dimen/viewsHeight"
          android:background="@drawable/edit_text_back"
          android:ems="10"
          android:hint="@string/write_a_comment"
          android:inputType="textPersonName"
          android:paddingStart="10dp"
          android:paddingEnd="10dp"
          android:layout_marginEnd="10dp"
          android:tag="regularFont"
          android:textColor="@color/black"
          android:textCursorDrawable="@null"
          app:layout_constraintEnd_toStartOf="@+id/sendBtn"
          app:layout_constraintStart_toStartOf="parent"
          app:layout_constraintBottom_toBottomOf="parent" />

      <TextView
          android:id="@+id/sendBtn"
          android:layout_width="@dimen/circleButtonDimension"
          android:layout_height="@dimen/circleButtonDimension"
          android:background="@drawable/yellow_circle"
          android:gravity="center"
          android:padding="@dimen/iconTextPadding"
          android:tag="icon"
          android:text="@string/sendIcon"
          android:textColor="@color/white"
          android:textSize="@dimen/iconTextSize"
          app:layout_constraintBottom_toBottomOf="parent"
          app:layout_constraintEnd_toEndOf="parent"/>

  </android.support.constraint.ConstraintLayout>


    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/dialogNameTxt"
        android:id="@+id/cancelDialogView"
        android:visibility="gone">

        <TextView
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="20dp"
            android:layout_marginTop="10dp"
            android:tag="regularFont"
            android:text="@string/confirm_cancel"
            android:textColor="@color/black"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/textView3"
            app:layout_constraintBottom_toTopOf="@id/yesBtn"/>

        <Button
            android:id="@+id/yesBtn"
            android:layout_width="0dp"
            android:layout_height="@dimen/viewsHeight"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/rounded_yellow_button"
            android:text="@string/yes"
            android:textAllCaps="false"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toStartOf="@+id/guideline4"
            app:layout_constraintStart_toStartOf="parent" />

        <Button
            android:id="@+id/noBtn"
            android:layout_width="0dp"
            android:layout_height="@dimen/viewsHeight"
            android:layout_marginStart="10dp"
            android:layout_marginEnd="10dp"
            android:layout_marginBottom="10dp"
            android:background="@drawable/rounded_yellow_button"
            android:text="@string/no"
            android:textAllCaps="false"
            android:textColor="@color/white"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="@+id/guideline4" />

        <android.support.constraint.Guideline
            android:id="@+id/guideline4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.5" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/errorIcon"
            android:textSize="60sp"
            android:textColor="@color/red"
            android:tag="icon"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </android.support.constraint.ConstraintLayout>

</RelativeLayout>

and here I set the background transparent for dialog in order to show my background

getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
hagar Mohamad
  • 97
  • 1
  • 11

2 Answers2

0

Use this

Solution 1

 recyclerView.addItemDecoration(new DividerItemDecoration(getContext(),
                    DividerItemDecoration.VERTICAL));

Solution 2

Declare a view like this in bottom of your item layout by setting layout gravity or below the text

    <View
         android:layout_width="match_parent"
         android:layout_height="1dp"
         android:background="@color/grey"></View>
Quick learner
  • 10,632
  • 4
  • 45
  • 55
0

The solution could be add bottomPadding for dialog background exactly the same like radius.

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/white"></solid>
    <corners android:radius="@dimen/viewsRadius"></corners>
    <padding android:bottom="@dimen/viewsRadius"/>
</shape>
Dmytro Ivanov
  • 1,260
  • 1
  • 8
  • 10