[英]Pass touch events to underlying view when click on transparent area, but allow clicks on buttons
I have a problem because I don't know how to make the transparent background of Fragment B pass on touch events to Fragment A: 我有一个问题,因为我不知道如何使片段B的透明背景将触摸事件传递给片段A:
Fragment C has Fragment B layered on top of Fragment A: Fragment C XML: 片段C在片段A的上方分层放置了片段B: 片段C XML:
...
<FrameLayout
android:id="@+id/fragment_A_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="@+id/fragment_B_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
...
And here is where Fragment C attaches the fragments to those FrameLayouts: Fragment C class: 这是片段C将片段附加到那些FrameLayouts的位置: 片段C类:
...
fragmentTransaction.add(R.id.fragment_A_container, FragmentA, TAG_FRAGMENT_A);
fragmentTransaction.add(R.id.fragment_B_container, FragmentB, TAG_FRAGMENT_B);
...
But now, I don't know how to only let the toolbar and floating action button get clicked, but the rest of the background pass on the click event to Fragment A? 但是现在,我不知道如何只单击工具栏和浮动操作按钮,但是其余的背景将click事件传递给片段A? Here is a basic idea of Fragment B's layout: FragmentB XML:
这是片段B布局的基本思想:片段B XML:
<LinearLayout
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.design.widget.FloatingActionButton/>
<android.support.v7.widget.Toolbar
android:layout_gravity="bottom"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
Thank you! 谢谢!
It actually did work, but I noticed that in my code, it was really doing this ( FragmentD
is an opaque background meant to go underneath FragmentA
and FragmentB
): 它确实有效,但是我注意到在我的代码中,它确实是这样做的(
FragmentD
是不透明的背景,意在FragmentA
和FragmentB
之下):
fragmentTransaction.add(R.id.fragment_A_container, FragmentD, TAG_FRAGMENT_D);
fragmentTransaction.add(R.id.fragment_A_container, FragmentA, TAG_FRAGMENT_A);
fragmentTransaction.add(R.id.fragment_B_container, FragmentB, TAG_FRAGMENT_B);
I would think that by adding FragmentD
and then adding FragmentA
to fragment_A_container
, FragmentA
should be on top of FragmentD
, but I guess it wasn't the case. 我认为,通过添加
FragmentD
, 然后将FragmentA
添加到fragment_A_container
, FragmentA
应该位于FragmentD
之上,但我想并非如此。 So I guaranteed that the order would be correct by separating them into their own FrameLayouts, and it worked fine: 因此,我通过将它们分成自己的FrameLayout来保证顺序正确,并且工作正常:
Updated XML: 更新的XML:
...
<FrameLayout
android:id="@+id/fragment_D_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="@+id/fragment_A_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
<FrameLayout
android:id="@+id/fragment_B_container"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.