Подтвердить что ты не робот

Обрезанная кнопка не получает сенсорный ввод

У меня есть FAB, который находится между двумя макетами. Используя отрицательный запас вместе с android:clipChildren и android:clipToPadding, оба установлены в false, я могу создать эту удобную маленькую кнопку:

enter image description here

Теперь проблема заключается в том, что нижняя половина FAB не получает сенсорный ввод или другим словом: не clickable. Я пробовал играть с 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 позволит указанному представлению рисовать вне его родительского макета, но любой сенсорный ввод все равно будет ограничен родительскими границами.

4b9b3361

Ответ 1

Вы должны переместить свой индекс FAB Z в макете, чтобы он находился на верхней части другого views на экране, поэтому, когда происходит событие касания, FAB должен получить событие касания перед другими видами.

и понять, почему он не получает события касания в нижней части FAB, потому что вы использовали android:clipChildren="false", поэтому на самом деле родительские ограничители меньше этого, но ничья происходит вне его, поэтому, когда прикосновение событие сначала принимается родительскому, затем оно пытается перенаправить его на нужный дочерний элемент, а событие касания должно находиться в границах родительского элемента, поэтому нижняя часть FAB находится за пределами границ родителя, а событие касания не для него.