我怎么会显示一个视图作为另一个重叠? [英] How would I display one view as an overlay of another?
问题描述
我有两个观点,即把整个屏幕,我想在同一时间,以显示这两种观点,一个在另一个之上。我的布置是这样的:
I have two views that take the whole screen and I want to display both views at the same time, one on top of the other. My layout looks like this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<WebView
android:id="@+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
<org.example.myCustomView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>
</LinearLayout>
注意 myCustomView
使用的OnDraw(这种方法的最后一条语句是无效的())来绘制自定义图形。我得到的问题是,它只是显示 myCustomView
,的WebView
是隐藏的。我试图改变的 mycustomView
的背景颜色为透明的,但这没什么区别。
Note that myCustomView
uses onDraw (this method last statement is invalidate()) to draw custom graphics. The problem I am getting is that it only displays myCustomView
, WebView
is hidden. I tried to change the background colour of mycustomView
to transparent but this makes no difference.
我也想有,使 myCustomView
作为的WebView
,反之亦然覆盖的能力。
I would also like to have the ability to make myCustomView
as an overlay on WebView
or vice versa.
推荐答案
使用 RelativeLayout的
对于初学者。
您可以使用 ViewGroup.addView(查看孩子,INT指数,ViewGroup.LayoutParams PARAMS)
或与变种ViewGroup.removeView(查看视图)
或 ViewGroup.removeViewAt(INT指数)
。
这显然需要您手动使用膨胀的意见 LayoutInflater
,但你可以保持一个全球参考每个充气后两者只需扳动。
This would obviously require you to inflate the views manually using LayoutInflater
but you could keep a global reference to each after inflating and just flip between the two.
这篇关于我怎么会显示一个视图作为另一个重叠?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!