【问题标题】:Delay Background Color in Top Sheet延迟顶页中的背景颜色
【发布时间】:2020-11-10 08:11:00
【问题描述】:

我正在尝试使顶部工作表中的两种背景颜色出现,但一种颜色延迟 10 秒。我尝试实现动画以延迟,但在完成此操作时遇到问题。

top_sheet_color_background.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
    <item android:top="200dp">
        <shape android:shape="rectangle" >
            <size android:height="10dp" />
            <corners
                android:topLeftRadius="0dp"
                android:topRightRadius="0dp"
                android:bottomLeftRadius="30dp"
                android:bottomRightRadius="30dp">
            </corners>
            <solid android:color="@android:color/holo_blue_bright" />
        </shape>
    </item>

    <item android:bottom="50dp">
        <shape android:shape="rectangle" >
            <size android:height="100dp" />
            <corners
                android:topLeftRadius="0dp"
                android:topRightRadius="0dp"
                android:bottomLeftRadius="30dp"
                android:bottomRightRadius="30dp">
            </corners>
            <solid android:color="@android:color/white" />
        </shape>
    </item>
</layer-list>

top_sheet.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/top_sheet"
    android:layout_width="match_parent"
    android:layout_height="450dp"
    android:orientation="vertical"
    android:padding="30dp"
    android:elevation="0dp"
    android:layout_margin="0dp"
    app:behavior_hideable="false"
    app:behavior_peekHeight="0dp"
    android:background="@drawable/top_sheet_color_background"
    app:layout_behavior="@string/top_sheet_auto_close_behavior">
</LinearLayout>

【问题讨论】:

    标签: android android-studio android-layout kotlin android-linearlayout


    【解决方案1】:

    您可以做的最简单和最快的方法是使用带有淡入淡出动画的选择器:

    <?xml version="1.0" encoding="utf-8"?>
    <selector xmlns:android="http://schemas.android.com/apk/res/android"
        android:exitFadeDuration="@android:integer/config_shortAnimTime">
    
        <item android:state_enabled="true" >
            <layer-list>
                <item android:top="200dp">
                    <shape android:shape="rectangle" >
                        <size android:height="10dp" />
                        <corners
                            android:topLeftRadius="0dp"
                            android:topRightRadius="0dp"
                            android:bottomLeftRadius="30dp"
                            android:bottomRightRadius="30dp">
                        </corners>
                        <solid android:color="@android:color/holo_blue_bright" />
                    </shape>
                </item>
    
                <item android:bottom="50dp">
                    <shape android:shape="rectangle" >
                        <size android:height="100dp" />
                        <corners
                            android:topLeftRadius="0dp"
                            android:topRightRadius="0dp"
                            android:bottomLeftRadius="30dp"
                            android:bottomRightRadius="30dp">
                        </corners>
                        <solid android:color="@android:color/white" />
                    </shape>
                </item>
            </layer-list>
        </item>
    
        <item>
            <shape android:shape="rectangle" >
                <size android:height="10dp" />
                <corners
                    android:topLeftRadius="0dp"
                    android:topRightRadius="0dp"
                    android:bottomLeftRadius="30dp"
                    android:bottomRightRadius="30dp">
                </corners>
                <solid android:color="@android:color/holo_blue_bright" />
            </shape>
        </item>
    </selector>
    

    在您的活动中,您只需设置延迟以启用视图:

    top_sheet.isEnabled = false
    top_sheet.postDelayed({
        top_sheet.isEnabled = true
    }, 1000) //animation delay
    

    【讨论】:

      猜你喜欢
      • 2018-10-25
      • 1970-01-01
      • 2021-06-10
      • 2021-12-10
      • 1970-01-01
      • 1970-01-01
      • 2015-04-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多