2

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

<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"/>

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

任何人都可以阐明应该如何做吗?

4

1 回答 1

5

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

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

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

为此,我们必须使用来自https://github.com/umano/AndroidSlidingUpPanel的 AndroidSlidingUpPanel

  • 如果您在将库包含在 AndroidStudio 中时遇到任何问题,您可以按照以下问题中的步骤操作:如何在 Android Stuido 中使用 Android 滑动面板制作示例演示项目

    <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"
        sothree:dragView="@+id/title">
    
  • 为了防止点击面板中的任何元素时向下滑动面板,最好将setdragView id设置为子元素的第一个元素

  • 使用以下代码为 textview 设置相同的 id "title"

    android:id="@+id/title"
    

上述步骤将确保仅当您单击 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);
    

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

于 2014-08-20T14:56:09.190 回答