MrH*_*rio 14 xml android button android-layout
我有一个位于两个布局之间的FAB.使用负边距android:clipChildren
并且android:clipToPadding
都设置为false我可以生成这个放置愉快的小按钮:
现在,问题是FAB的下半部分没有接收到触摸输入或换句话说:不可点击.我已经尝试过android:elevation
确保它尽可能保持最高的Z值,但问题仍然存在.与此同时,上半年工作正常.
我有点坚持这个,有谁可以帮助我做什么?下面是我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>
Run Code Online (Sandbox Code Playgroud)
任何帮助将不胜感激.如果您需要更多细节,我也很乐意提供更多.
提前致谢!
编辑:感谢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>
Run Code Online (Sandbox Code Playgroud)
如果有一件事需要从这里学习,那就是:设置android:clipChilden
为false
允许所述视图在其外部绘制父级布局但是任何触摸输入仍然仅限于父级边界.
您应该将布局中的 Z 索引移动到屏幕中FAB
另一个的顶部,这样当触摸事件发生时,应该在另一个视图之前接收到触摸事件。views
FAB
并理解为什么它没有在 FAB 的底部接收触摸事件,因为您确实使用了android:clipChildren="false"
所以实际上父边界比该边界小,但是绘制发生在它的外侧,所以当父边界接收到触摸事件时首先,它尝试将其转移到所需的子级,并且触摸事件必须在父级边界内,因此 FAB 的底部位于父级边界之外,并且触摸事件不适合他。