如何让滑动面板中的元素监听点击事件

for*_*t17 2 android android-layout android-fragments android-activity slidingpanelayout

我使用 AndroidSlidingPanel 库“ https://github.com/umano/AndroidSlidingUpPanel ”创建了一个演示应用程序,并将textview 作为孩子。问题是当我尝试单击标签面板向下滑动时无法单击标签。

<com.sothree.slidinguppanel.SlidingUpPanelLayout
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:panelHeight="68dp"
sothree:shadowHeight="4dp">

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:text="Main Content"
    android:textSize="16sp" />

<TextView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center|top"
    android:text="The Awesome Sliding Up Panel"
    android:textSize="16sp" 
    android:onClick="ClickedOnLabel"
    android:clickable="true"/>
Run Code Online (Sandbox Code Playgroud)

我遇到过类似的帖子“无法单击 SlidingUpPanelLayout 中的子按钮”,但不明白 setdragview 是什么?它有什么作用?

任何人都可以抛出一些光应该怎么做?

for*_*t17 5

两天后我学到了一个教训,在使用任何库之前,请阅读完整的文档并查看演示。

如果有人不得不面对类似的问题,我会回答这篇文章。

考虑这样一种情况,当点击谷歌地图中的任何标记时,我们必须开发类似于谷歌地图的一个面板,从底部弹出一个面板,其中包含商店的描述和街景。

为了做到这一点,我们必须使用来自https://github.com/umano/AndroidSlidingUpPanel 的AndroidSlidingUpPanel

上述步骤将确保只有当您单击 id 'title' 的 textview 时,才会发生面板的向下/向上滑动

  • 为了侦听滑动面板上的点击事件,请确保将 android:clickable=true 其设置为布局或元素

  • 为了有锚点,这意味着不是完全打开面板,而是将滑动面板打开到所需的位置,您可以使用以下代码。

    SlidingUpPanelLayout slidingUpPanelLayout =   (SlidingUpPanelLayout)
    findViewById(R.id.sliding_layout);
    
                //Setting the achor point to the middle of the screen
    
                slidingUpPanelLayout.setAnchorPoint(0.3f);
    
    Run Code Online (Sandbox Code Playgroud)

以防万一如果有人有同样的问题并且一直在谷歌搜索,这将是一个好的开始:)