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>
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.
I would also like to have the ability to make myCustomView
as an overlay on WebView
or vice versa.
An overlay is an extra layer that sits on top of a View (the "host view") which is drawn after all other content in that view (including children, if the view is a ViewGroup).
Simply use RelativeLayout or FrameLayout . The last child view will overlay everything else. Android supports a pattern which Cocoa Touch SDK doesn't: Layout management.
FrameLayout is designed to block out an area on the screen to display a single item. Generally, FrameLayout should be used to hold a single child view, because it can be difficult to organize child views in a way that's scalable to different screen sizes without the children overlapping each other.
Use a RelativeLayout
for starters.
You could use the ViewGroup.addView(View child, int index, ViewGroup.LayoutParams params)
or a variant along with ViewGroup.removeView(View view)
or ViewGroup.removeViewAt(int index)
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With