Как использовать украшение элемента в recyclerview в диалоговом окне с закругленными углами и прозрачным фоном

Я использую диалоговое окно, и в этом диалоговом окне я использую recyclerview, а также устанавливаю собственный фоновый рисунок с закругленными углами для этого диалогового окна. проблема в том, что всякий раз, когда я пытаюсь установить украшение элемента для recyclerview, он показывает некоторые странные линии в нижних углах диалога, например, здесь 1 и здесь 2 Я думаю, это потому, что я сделал фон диалога прозрачным. Я хочу знать, как удалить эти строки

Украшение предмета

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);
        }
    }

фон для диалога

<?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>

Макет для диалога

<?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>

и здесь я установил прозрачный фон для диалога, чтобы показать мой фон

getWindow().requestFeature(Window.FEATURE_NO_TITLE);
getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));

можете ли вы попытаться передать отступы в RecyclerView из Xml Layout, это поможет

Ankitkumar Makwana 28.05.2019 13:46

@ankitkumar-makwana Я не понимаю, что ты имеешь в виду?

hagar Mohamad 28.05.2019 14:26
0
2
588
2
Перейти к ответу Данный вопрос помечен как решенный

Ответы 2

Использовать этот

Решение 1

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

Решение 2

Объявите такое представление в нижней части макета вашего элемента, установив гравитацию макета или под текстом.

    <View
         android:layout_width = "match_parent"
         android:layout_height = "1dp"
         android:background = "@color/grey"></View>

к сожалению, это не решает мой вопрос, строка по-прежнему появляется всякий раз, когда я прокручиваю recyclerview, например здесь, если я использовал разделительItemDecoration вместо моего пользовательского оформления

hagar Mohamad 28.05.2019 13:36

не могли бы вы указать здесь свой код для настройки фона диалогового окна?

Quick learner 28.05.2019 13:50

и установите этот фоновый рисунок для recyclerview вместо диалога

Quick learner 28.05.2019 13:50

Я использую собственный макет для диалога, где я добавляю фон

hagar Mohamad 28.05.2019 14:07

Я отредактировал вопрос и добавил его, пожалуйста, проверьте его .. хорошо, я постараюсь добавить его в recyclerview

hagar Mohamad 28.05.2019 14:11
stackoverflow.com/questions/11864162/…
Quick learner 28.05.2019 14:17
Ответ принят как подходящий

Решением может быть добавление bottomPadding для фона диалога точно так же, как и радиус.

<?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>

Другие вопросы по теме