【问题标题】:SlidingDrawer Content touch not workingSlidingDrawer 内容触摸不起作用
【发布时间】:2015-09-11 06:49:07
【问题描述】:

我在我的活动中使用滑动抽屉进行交互。

<SlidingDrawer
        android:id="@+id/sdDrawerLeft"
        android:layout_width="80dp"
        android:layout_height="match_parent"
        android:layout_gravity="left"
        android:content="@+id/sdLeftContent"
        android:handle="@+id/sdLeftHandle"
        android:orientation="horizontal"
        android:rotation="180" >

        <ImageView
            android:id="@+id/sdLeftHandle"
            android:layout_width="20dp"
            android:layout_height="50dp"
            android:background="@drawable/shape_rounded_corners_gray_right"
            android:rotation="180"
            android:scaleType="center"
            android:src="@drawable/icon_arrow_left" />

        <LinearLayout
            android:id="@+id/sdLeftContent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="true"
            android:orientation="vertical"
            android:rotation="180"
            android:weightSum="1" >

            <requestFocus />

            <ImageView
                android:id="@+id/imgFavourite"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight=".1"
                android:background="@drawable/border_image"
                android:clickable="true"
                android:scaleType="center"
                android:src="@drawable/icon_content_like" />

            <ImageView
                android:id="@+id/imgFolder"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight=".1"
                android:background="@drawable/border_image"
                android:clickable="true"
                android:scaleType="center"
                android:src="@drawable/icon_content_add_folder" />

            <ImageView
                android:id="@+id/imgShare"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight=".1"
                android:background="@drawable/border_image"
                android:clickable="true"
                android:scaleType="center"
                android:src="@drawable/icon_content_share" />

            <ImageView
                android:id="@+id/imgComment"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_margin="10dp"
                android:layout_marginBottom="5dp"
                android:layout_marginTop="5dp"
                android:layout_weight=".1"
                android:background="@drawable/border_image"
                android:clickable="true"
                android:scaleType="center"
                android:src="@drawable/icon_content_comment" />

        </LinearLayout>
    </SlidingDrawer>

我正在做一些点击这些 Imageviews 的操作。但是当我点击这些 ImageViews 滑动内容后面的屏幕会得到触摸事件。我已经使这些图像视图可点击,但没有得到像 onClick 和 onTouch 这样的事件。

提前致谢

【问题讨论】:

    标签: android android-layout android-view


    【解决方案1】:

    首先,你已经添加了

    android:clickable="true" 为您的LinearLayout。如果这是可取的

    尝试添加

    android:descendantFocusability="blocksDescendants"SlidingDrawer 标签,

    如果这不起作用,请保持原样,然后添加,

            android:focusable="false"
            android:focusableInTouchMode="false"
    

    对于您设置为可点击的每个ImageView

    这似乎是一个没有那么优雅的解决方案的问题。我能够找到一个解决方案来拦截窗口上的完整事件并采取相应的行动。

    请查看我找到的the solution

    【讨论】:

    • @unflagged.destination 您是否尝试从您的LinearLayout 中删除android:clickable="true"?。也尝试制作ImageViews android:clickable=false。 A 我可以看到混淆基本上是 LinearLayout 中的 android:clickable="true" 并在其中再次具有可点击元素
    猜你喜欢
    • 2017-05-17
    • 2014-05-27
    • 2016-02-28
    • 2013-07-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多