대화 상자를 사용하고 있으며이 대화 상자에서 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));
-
답변 # 1
-
답변 # 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>
이 솔루션은 반경과 정확히 같은 대화 상자 배경에 bottomPadding을 추가 할 수 있습니다.