提问者:小点点

有什么方法可以让我在另一个视图之上按一段时间打开另一个视图吗



共1个答案

匿名用户

要在android中创建类似的内容,您可以使用带有自定义布局的alertDialog并模糊背景:custom_layout

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:orientation="vertical"
                  android:paddingLeft="30dp"
                  android:paddingRight="30dp"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent">
        <ImageView
            android:id="@+id/imageView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"/>
        <LinearLayout
                  android:orientation="horizontal"
                  android:paddingLeft="10dp"
                  android:paddingRight="10dp"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">
        <Button
            android:id="@+id/button1"
            android:layout_below
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <Button
            android:id="@+id/button2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        </LinearLayout>
     </LinearLayout>

在activity:

        //create an alert builder
            AlertDialog.Builder builder = new AlertDialog.Builder(this);
            builder.setTitle("Name"); //you can add this to your custom layout only
        // set the custom layout
            final View view = getLayoutInflater().inflate(R.layout.custom_layout, null);
            builder.setView(view);
            Button button1 = (Button) view.findViewById(R.id.button1); // etc.. for button2,3,4.
        // onclick functions
        // create and show the alert dialog
            AlertDialog dialog = builder.create();
            dialog.show();

对于模糊背景,您可以添加一个主题,如https://stackoverflow.com/a/41373144/7364284,但是,我建议使用窗口属性,如https://stackoverflow.com/a/10381077/7364284,因为它代码少且易于使用。