I have 2 views that takes the whole screen and I want to display both views at the same time. 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 that it only display myCustome view and webView is hidden. I tried to change the background color of mycustomView to transparent but this makes no difference.I would also the abilty to make mycustomeView as overlay on webView or vice versa.


answer one:

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.


answer two:

I'm not sure if you can do this when they are in the same xml file, but I know that if you move:
<org.example.myCustomView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>

to another xml file, and create another activity. set the content view to the xml file that contains the org.example.myCustomView and call that activity. in the manifest, when you add that activity, add a theme statement as so:

android:theme="@android:style/Theme.Dialog"

the full statement should look like this:

<activity android:name=".name_of_activity"
android:label="TextToBeOnTop"
android:theme="@android:style/Theme.Dialog">
</activity>

the result will look like this (only it will be with your components instead):

In Android how to display one view as overlay on top of another view?_第1张图片






更多相关文章

  1. Android 图片左上角、右上角标签tag
  2. Android本地图片压缩+转base64
  3. Android大图片加载处理
  4. android WebView 拍照上传图片兼容
  5. android旋转图片
  6. Android圆角图片封装类(直接使用)
  7. Android 图片缩放实例详解
  8. android获取图库图片并返回

随机推荐

  1. android编辑单个工程
  2. android 焦点问题
  3. 如何让Android中的 Base64工具类支持2.2
  4. EditText
  5. android 如何在状态栏上增加一个icon
  6. Android的ADT的安装
  7. android 测试简介
  8. Android单元测试详解(以公司产品demo为案
  9. Android中Dialog的使用
  10. android 中edittext设置不弹出软键盘