如何在另一个布局上放置透明视图



我正在处理表面视图。我想要在我的表面视图上有一个透明的视图。该透明视图必须包含标题、说明和微调器三件事以及一个按钮名称"开始"。如果不输入标题,描述和Spinner的菜单,则无法进入透明视图下方的下一个布局。请帮我举一些例子。如何实现这样的观点???这就是我想要的..在此处输入图像描述

这是"我的表面视图"布局。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">

<LinearLayout
android:id="@+id/suface_view_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<net.ossrs.yasea.SrsCameraView
android:id="@+id/glsurfaceview_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</LinearLayout>

使用FrameLayout而不是RelativeLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
// Add other view
<LinearLayout
android:id="@+id/suface_view_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">

<net.ossrs.yasea.SrsCameraView
android:id="@+id/glsurfaceview_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</LinearLayout>
</FrameLayout>

你可以像这样使用

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/suface_view_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<net.ossrs.yasea.SrsCameraView
android:id="@+id/glsurfaceview_camera"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" />
</LinearLayout>
<view 
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"/>
</RelativeLauout>
You can place FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
</RelativeLayout>

or You can place View

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<View
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</View>

</RelativeLayout>
FrameLayout is the better option 

使用 RelativeLayout 或 FrameLayout 可以在 SurfaceView 上方放置另一个布局,为了使布局透明,以使下面的 SurfaceView 部分可见,我们必须将 alpha 设置为布局的背景颜色。我们可以通过更改颜色代码使特定颜色透明。

通常颜色代码将采用这种格式,

         RR   GG  BB     或       R G B      

例如: # ff    00 00         或    # f      f 0     

它告诉绿色蓝色红色值从0f(十六进制)

我们还有一种颜色代码格式来设置 alpha 值来更改颜色的不透明度,

       AA  RR   GG  BB     或      A   R    G B   

例如:# ffff    00    00         或    # 0 f      f 0         

它告诉阿尔法绿蓝红值从 0 到 f(十六进制)

因此,为了使任何颜色透明,我们可以将 alpha 的值从 0 更改为 f。 例如:考虑我们想使黑色透明,

  黑色的颜色代码是#000000,以使其透明,将其更改为

  • #00000000- 完全透明
  • #88000000- 部分透明
  • #ff000000- 无透明度

将此颜色设置为布局以使其透明。

最新更新