【问题标题】:How to hide the Umano SlidingupPanel when clicking outside the panel在面板外单击时如何隐藏 Umano SlidingupPanel
【发布时间】:2014-11-29 10:40:14
【问题描述】:

AndroidSlidingUpPanel

在这里,我使用的是上滑面板库。您可以在以下屏幕中看到面板和列表视图。如果我在面板外部单击(暗区),我想要做的是隐藏面板。相反,它是单击上述布局中的列表视图。我怎样才能做到这一点?

这里是 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/com.voucher.point.activity"
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical" >

<!-- sothree:dragView="@+id/dragView" -->

<com.sothree.slidinguppanel.SlidingUpPanelLayout
    xmlns:sothree="http://schemas.android.com/apk/res-auto"
    android:id="@+id/sliding_layout"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:gravity="bottom"
    app:fadeColor="@color/transparent"
    sothree:panelHeight="40dip"
    sothree:paralaxOffset="200dp" >

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@color/white"
        android:orientation="vertical" >

        <ListView
            android:id="@+id/offersList"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:scrollbars="none"
            android:visibility="gone" >
        </ListView>

    </LinearLayout>

    <include
        android:id="@+id/bottom_menu"
        android:layout_width="fill_parent"
        android:layout_height="270dip"
        layout="@layout/side_menu" />
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

我可以这样做吗?

【问题讨论】:

  • 您好,我也遇到了同样的问题,如果您找到任何解决方案,请分享?
  • 嗨 Rethinavel Pillai,我需要这种实现。你能分享一下这个实现的核心代码吗?

标签: android android-sliding slidingpanelayout


【解决方案1】:

对于 3.3.0 及更高版本,可以通过以下方式做到这一点

final SlidingUpPanelLayout slidingUpPanelLayout = (SlidingUpPanelLayout) findViewById(R.id.sliding_layout);
slidingUpPanelLayout.setFadeOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
    }
});

source

【讨论】:

  • 太棒了!完美运行
  • 但是这个监听器绕过了滑动手势!!
【解决方案2】:

我相信你已经解决了你的问题,但对于其他有相同要求的人,我在我的地图顶部添加了另一个 View(在 xml 布局中)并设置它的触摸点击能力。

所以我的xml文件是这样的:

<com.sothree.slidinguppanel.SlidingUpPanelLayout
        android:id="@+id/sliding_layout"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/booking_confirm_layout"
        android:gravity="bottom"
        app:umanoFadeColor="@color/black_75_percent"
        app:umanoOverlay="true"
        app:umanoPanelHeight="111dp"
        app:umanoShadowHeight="0dp">

        <FrameLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <com.google.android.gms.maps.MapView
                android:id="@+id/map_view"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_marginBottom="96dp" />

            <View
                android:id="@+id/mapCover"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:background="@android:color/transparent"/>
        </FrameLayout>

 <LinearLayout>
.
.
.
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

在代码中:

this.mMapCover = findViewById(R.id.mapCover);
        this.mMapCover.setOnTouchListener(new View.OnTouchListener()
        {
            @Override
            public boolean onTouch(View v, MotionEvent event)
            {
                if (mSlidingPanel.getPanelState() != PanelState.COLLAPSED)
                {
                    mSlidingPanel.setPanelState(PanelState.COLLAPSED);
                    return true;
                }

                return false;
            }
        });

【讨论】:

    【解决方案3】:
    //to hide when you touch overlay
    
        mLayout.setFadeOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                mLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
            }
        });
    

    【讨论】:

      【解决方案4】:

      完全隐藏

      mLayout.setFadeOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              mLayout.setPanelState(SlidingUpPanelLayout.PanelState.HIDDEN);
          }
      });
      

      【讨论】:

        【解决方案5】:

        你可以添加一个 onClickListener 或 onTouchListener 到外部面板和 ontouch 或 oncick 调用slidingPanelLayout.expandPane(0)

        findViewById(R.id.bg_panel).setOnTouchListener(new OnTouchListener() {
        
                    @Override
                    public boolean onTouch(View v, MotionEvent event) {
        
                        slidingPanelLayout.expandPane(0);
                        return false;
                    }
        

        【讨论】:

          【解决方案6】:

          回答的代码对我不起作用。不幸的是,此事件未捕获对我的部分 UI 的点击。

          为此,为主要内容(SlidingUpPanelLayout 的第一个子项)设置一个 id 并调用它:

          findViewById(R.id.main_content).setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          if(slidingUpPanelLayout.getPanelState() != SlidingUpPanelLayout.PanelState.COLLAPSED){
                              slidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
                          }
                      }
                  });
          

          【讨论】:

            【解决方案7】:

            您的向上滑动面板包含整个屏幕,然后是您如何检测屏幕外的点击。如果您仅将其定位为“HideMenu”和“ShowMenu”,则可以这样做。

            否则,使用全屏上滑面板,您可以通过单击返回 android 按钮或面板上的任何单击事件来隐藏它。

            如果我的回答不能解决您的问题,请告诉我。

            享受编码... :)

            【讨论】:

              猜你喜欢
              • 2019-02-07
              • 2014-05-02
              • 2014-01-03
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2018-02-18
              • 1970-01-01
              • 2016-12-25
              相关资源
              最近更新 更多