操作系统终止我的活动后,SlidingUpPanelLayout不会在恢复时崩溃

Ken*_*ent 5 android android-layout android-activity

我使用的是SlidingUpPanelLayout库的最新版本(3.0).如果它在后台运行,Android OS会定期杀死我的Activity(按Home而不是Back退出).如果发生这种情况,并且当用户上次使用该应用程序时面板已展开,则面板在创建时仍会展开,但内部的所有内容都将消失.基本上是一个空白的屏幕.

在这种情况下,我实际上想要将活动重置为它的初始状态(完全退出后打开),这是崩溃的.但我无法让它发挥作用.在布局xml中,我将初始状态设置为折叠.

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="bottom"
    sothree:umanoPanelHeight="48dp"
    sothree:umanoShadowHeight="4dp"
    sothree:umanoInitialState="collapsed" >
Run Code Online (Sandbox Code Playgroud)

我也放了这条线

slidingUpPanelLayout.setPanelState(PanelState.COLLAPSED);
Run Code Online (Sandbox Code Playgroud)

在onCreate()的几个地方,但面板没有崩溃.我在每次折叠尝试之前和之后打印了面板状态,发现即使在第一次折叠尝试之前,panelState实际上也设置为折叠,即使它没有折叠.

那么这是图书馆中的一个错误,还是我做错了什么.

谢谢你的帮助.

小智 1

您需要重写 onResume 事件,然后调用折叠操作。下面的代码应该可以完成这项工作:

@Override
protected void onResume() {
    super.onResume();
    slidingUpPanelLayout.setPanelState(PanelState.COLLAPSED);
}
Run Code Online (Sandbox Code Playgroud)