剪切按钮不接收触摸输入

时间:2014-11-19 06:11:34

标签: android xml android-layout button

我有一个位于两个布局之间的FAB。使用负边距与android:clipChildrenandroid:clipToPadding同时设置为false我能够生成这个放置得很好的小按钮:

enter image description here

现在,问题是FAB的下半部分没有接收到触摸输入或换句话说:不可点击。我尝试过使用android:elevation,确保它尽可能保持最高的Z值,但问题仍然存在。与此同时,上半年工作得很好。

enter image description here

我有点坚持这个,这里的任何人都可以帮助我做什么吗?如果需要,下面是我的XML布局。

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false">

    <id.ridsatrio.taggr.widgets.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:clipToPadding="false">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <id.ridsatrio.taggr.widgets.SquaredImageView
                android:id="@+id/iv_details_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:adjustViewBounds="true"
                android:background="?android:attr/selectableItemBackground"
                android:clickable="true"
                android:contentDescription="Album Art Image"
                android:elevation="@dimen/elevation_none"
                android:focusable="true"
                android:scaleType="centerCrop"
                android:src="@drawable/def_album_art" />

            <View
                android:id="@+id/v_anchor"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_header_height"
                android:layout_below="@+id/iv_details_header"
                android:elevation="@dimen/elevation_low" />

            <LinearLayout
                android:id="@+id/ll_track_fields"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/v_anchor"
                android:orientation="vertical">

                ...

            </LinearLayout>

            <View
                android:id="@+id/v_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_section_divider_height"
                android:layout_below="@id/ll_track_fields"
                android:layout_marginLeft="@dimen/details_section_divider_margin_start"
                android:layout_marginTop="@dimen/item_horizontal_margin_xlarge"
                android:background="@color/dividers_light" />

            <LinearLayout
                android:id="@+id/ll_album_fields"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/v_divider"
                android:orientation="vertical">

                ...

            </LinearLayout>

            <RelativeLayout
                android:id="@+id/rl_header"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_header_height"
                android:layout_gravity="center_horizontal"
                android:background="@color/primary"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:elevation="@dimen/elevation_low">

                ...

                <com.melnykov.fab.FloatingActionButton
                    android:id="@+id/fab_details"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_alignParentBottom="true"
                    android:layout_alignParentLeft="true"
                    android:layout_marginBottom="@dimen/details_header_fab_margin_bottom"
                    android:layout_marginLeft="@dimen/details_header_fab_margin_start"
                    android:background="?android:attr/selectableItemBackground"
                    android:elevation="@dimen/elevation_medium"
                    android:src="@drawable/ic_action_down"
                    fab:fab_colorNormal="@color/primary_dark"
                    fab:fab_colorPressed="@color/primary"
                    fab:fab_type="mini" />

            </RelativeLayout>

        </RelativeLayout>

    </id.ridsatrio.taggr.widgets.ObservableScrollView>

    ...

</RelativeLayout>

非常感谢任何帮助。如果您需要更多详细信息,我也很乐意提供更多信息。

提前致谢!


修改:感谢 MoshErsan ,我终于能够实现这一目标。这是我的工作XML以防万一遇到与我相同的问题:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:fab="http://schemas.android.com/apk/res-auto"
    android:id="@+id/rl_root"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:clipChildren="false"
    android:clipToPadding="false">

    <id.ridsatrio.taggr.widgets.ObservableScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:fab="http://schemas.android.com/apk/res-auto"
        android:id="@+id/sv_content"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:clipChildren="false"
        android:clipToPadding="false">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="?android:attr/windowBackground"
            android:clipChildren="false"
            android:clipToPadding="false"
            android:focusable="true"
            android:focusableInTouchMode="true">

            <id.ridsatrio.taggr.widgets.SquaredImageView
                android:id="@+id/iv_details_header"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentTop="true"
                android:adjustViewBounds="true"
                android:background="?android:attr/selectableItemBackground"
                android:clickable="true"
                android:contentDescription="Album Art Image"
                android:elevation="@dimen/elevation_none"
                android:focusable="true"
                android:scaleType="centerCrop"
                android:src="@drawable/def_album_art" />

            <View
                android:id="@+id/v_anchor"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_header_height"
                android:layout_below="@+id/iv_details_header"
                android:elevation="@dimen/elevation_low" />

            <LinearLayout
                android:id="@+id/ll_track_fields"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@+id/v_anchor"
                android:orientation="vertical">

                ...

            </LinearLayout>

            <View
                android:id="@+id/v_divider"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_section_divider_height"
                android:layout_below="@id/ll_track_fields"
                android:layout_marginLeft="@dimen/details_section_divider_margin_start"
                android:layout_marginTop="@dimen/item_horizontal_margin_xlarge"
                android:background="@color/dividers_light" />

            <LinearLayout
                android:id="@+id/ll_album_fields"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_below="@id/v_divider"
                android:orientation="vertical">

                ...

            </LinearLayout>

            <RelativeLayout
                android:id="@+id/rl_header"
                android:layout_width="match_parent"
                android:layout_height="@dimen/details_header_height"
                android:layout_gravity="center_horizontal"
                android:background="@color/primary"
                android:clipChildren="false"
                android:clipToPadding="false"
                android:elevation="@dimen/elevation_low">

                ...

            </RelativeLayout>

            <com.melnykov.fab.FloatingActionButton
                android:id="@+id/fab_details"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignBottom="@+id/rl_header"
                android:layout_alignLeft="@+id/rl_header"
                android:layout_marginBottom="@dimen/details_header_fab_margin_bottom"
                android:layout_marginLeft="@dimen/details_header_fab_margin_start"
                android:background="?android:attr/selectableItemBackground"
                android:elevation="@dimen/elevation_medium"
                android:src="@drawable/ic_action_down"
                fab:fab_colorNormal="@color/primary_dark"
                fab:fab_colorPressed="@color/primary"
                fab:fab_type="mini" />

        </RelativeLayout>

    </id.ridsatrio.taggr.widgets.ObservableScrollView>

    ...

</RelativeLayout>

如果有什么需要从这里学习的话:android:clipChilden设置为false将允许所述视图在其外部绘制父级布局但是任何触摸输入仍然仅限于父母的边界。

1 个答案:

答案 0 :(得分:3)

您应该将布局中的FAB Z索引移到屏幕中另一个views的顶部,这样当触摸事件发生时,FAB应该会接触到另一个观点之前的事件。

并且理解为什么它没有在FAB的底部接收触摸事件,因为你确实使用了android:clipChildren="false"所以实际上父版本比较小,但是抽奖发生在它旁边,因此,当首先接收到父母的触摸事件时,它会尝试将其转移到所需的孩子,并且触摸事件必须在父母的Bounders中,因此FAB的底部部分位于父母的bounders之外,并且触摸事件不适合他。

相关问题