带有圆角的弹出窗口,不会剪辑孩子们

zphenhs4  于 2021-08-20  发布在  Java
关注(0)|答案(0)|浏览(221)

我有一个圆角弹出窗口,我想在某些情况下显示。

private void setPopUpWindow(final View v) {
    LayoutInflater inflater = (LayoutInflater) v.getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    View view = inflater.inflate(R.layout.popup_edit_car, null);

    TextView manual = (TextView) view.findViewById(R.id.txt_manual);
    TextView automatic = (TextView) view.findViewById(R.id.txt_automatic);

    //Here is the round Corner
    Drawable background = ContextCompat.getDrawable(requireContext(), R.drawable.popup_background);

    myPopupWindow = new PopupWindow(view, RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT, true);

    myPopupWindow.setBackgroundDrawable(background);

    myPopupWindow.setClippingEnabled(true);
}

布局如下:

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/lay_popup_container"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:clipChildren="false">

<TextView
    android:id="@+id/txt_popup_title"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:padding="@dimen/medium_layout_spacing"
    android:text="@string/dummy_car_transmission"
    android:textAppearance="?attr/textAppearanceHeadline6"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toTopOf="parent" />

<View
    android:id="@+id/popup_title_divider"
    android:layout_width="0dp"
    android:layout_height="1dp"
    android:background="@color/grey_400"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_popup_title" />

<TextView
    android:id="@+id/txt_manual"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:gravity="center_vertical"
    android:padding="@dimen/general_layout_spacing"
    android:text="@string/manual"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/popup_title_divider" />

<TextView
    android:id="@+id/txt_automatic"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:background="@color/grey_300"
    android:gravity="center_vertical"
    android:padding="@dimen/general_layout_spacing"
    android:text="@string/automatic"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent"
    app:layout_constraintTop_toBottomOf="@+id/txt_manual" />
</androidx.constraintlayout.widget.ConstraintLayout>

问题是,当textview具有 android:background .
弹出窗口如下图所示:

主窗口未剪切最后一个文本视图。同时,其他文本视图 txt_popup_titletxt_manual 主窗口剪辑正确,因为它们没有任何 android:background .
需要帮忙吗?

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题