Как создать DialogFragment с прозрачной частью? - PullRequest
0 голосов
/ 30 октября 2019

Как мне создать превосходную часть этого дизайна? Я делаю это во всплывающем окне с использованием DialogFragment, но я не могу добиться эффекта прозрачности вверху.

enter image description here Дизайн кнопки, но background_circle:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="#fff"/>

</shape>

Со следующим XML-файлом my_dialog:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="30dp"
        android:padding="10dp"
        android:orientation="vertical"
        android:background="#fff"
        android:gravity="center">

        <TextView
            android:layout_marginTop="50dp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="text long text"
            />

        <Button
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Button"/>

    </LinearLayout>


    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:background="@drawable/background_circle"
        android:padding="3dp"
        android:src="@drawable/ic_empty_star"/>
</RelativeLayout>

Результат: enter image description here Звезда должна быть с верхней частью вне макета.

Ответы [ 2 ]

1 голос
/ 31 октября 2019

Это просто .. мой друг

enter image description here

просто установите фон диалога по умолчанию прозрачным, как я это делал в onStart ()

class TestDialog: DialogFragment() {

        override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
            return inflater.inflate(R.layout.my_dialog, container)
        }

        override fun onStart() {
            super.onStart()
            // if you want your dialog's width/height match device screen's width/height
            // dialog?.window?.setLayout(
            //    ViewGroup.LayoutParams.MATCH_PARENT,
            //    ViewGroup.LayoutParams.WRAP_CONTENT
            // )

            dialog?.window?.setBackgroundDrawable(ColorDrawable(Color.TRANSPARENT))
        }
    }

Ваш диалог .xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_margin="30dp"
            android:padding="10dp"
            android:orientation="vertical"
            android:background="#fff"
            android:gravity="center">

                <TextView
                    android:layout_marginTop="50dp"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="text long text"
                    />

                <Button
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text="Button"/>

            </LinearLayout>


        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="@drawable/background_circle"
            android:padding="3dp"
            android:src="@drawable/ic_account_circle_black_54dp"/>

</RelativeLayout>

background_circle.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="oval">

    <solid
        android:color="#fff"/>

</shape>
0 голосов
/ 31 октября 2019

Это может быть грубое решение, но как насчет использования размытого вида позади всплывающего окна?

Проверьте эту библиотеку.

https://github.com/mmin18/RealtimeBlurView

...