如何使滑动面板中的元素听取单击事件

时间:2014-08-15 12:38:03

标签: android android-layout android-activity android-fragments slidingpanelayout

我使用AndroidSlidingPanel Library" 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"/>

我遇到了类似的帖子&#34; Can't click children button in SlidingUpPanelLayout&#34;但是无法理解setdragview是什么?它的作用是什么?

任何人都可以说明应该怎么做?

1 个答案:

答案 0 :(得分:4)

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

如果有人不得不面对类似的问题,我正在回复此帖。

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

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

  • 如果您在AndroidStudio中包含库时遇到任何问题,可以按照以下问题中的步骤进行操作how to make a sample demo project with Android Sliding panel in Android Stuido

    <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设置为子元素的第一个元素,最好是

  • 使用以下代码

    将相同的ID“title”设置为textview
    android:id="@+id/title"
    

上述步骤将确保只有在您点击ID“title”的文本视图时才会向下滑动/向上滑动

  • 为了收听滑动面板上的点击事件,请确保 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);
    

如果有人遇到同样的问题并且一直在谷歌上搜索,这将是一个良好的开端:)