【问题标题】:how to make the elements in the sliding panel listen to the click events如何让滑动面板中的元素监听点击事件
【发布时间】:2014-08-15 12:38:02
【问题描述】:

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

我遇到过类似的帖子“Can't click children button in SlidingUpPanelLayout”但不明白 setdragview 是什么?它的作用是什么?

谁能说明应该怎么做?

【问题讨论】:

  • 谁能帮我解决这个问题:)

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


【解决方案1】:

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

如果有人不得不面对类似的问题,我正在回答这个帖子。

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

为了做到这一点,我们必须使用来自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设置为子元素的第一个元素

  • 使用以下代码为 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);
    

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多