【问题标题】:How to put a transparent view on another Layout如何将透明视图放在另一个布局上
【发布时间】:2017-05-25 05:06:57
【问题描述】:

我正在处理 Surface 视图。我想在我的表面视图上有一个透明视图。该透明视图必须包含标题、描述和微调器三项内容以及一个名为“开始”的按钮。如果不输入标题、描述和 Spinner 的菜单,就无法进入该透明视图下方的下一个布局。请帮我举一些例子..如何实现这种观点???这就是我想要的..enter image description here

这是我的 Surfaceview 布局..

  <?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>

【问题讨论】:

  • 你不需要没用的LinearLayout。

标签: android android-layout surfaceview glsurfaceview


【解决方案1】:

使用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>

【讨论】:

  • 伙计...它的作品...我拿了一个 FrameLayout (A),我把这 4 个东西放进去了,我拿了一个 FrameLayout (B),就像你对我的相机视图说的那样......我简单地将布局 A 包含在布局 B 中并得到了想要的结果......非常感谢......
  • 还有一个问题.. 检查标题是否有效后如何关闭布局A?假设我输入标题并在单击按钮后我想禁用该布局并切换到布局 B??
  • 您可以使用视图Visibility。只需设置可见性GONE
【解决方案2】:

你可以像这样使用

 <?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>

【讨论】:

    【解决方案3】:
     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 
    

    【讨论】:

      【解决方案4】:

      使用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

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

      它告诉 Alpha Green Blue Red 值从 0 到 f(十六进制)

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

        黑色的颜色代码是#000000,为了让它透明改为

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

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

      【讨论】:

        猜你喜欢
        • 2021-11-24
        • 2023-03-03
        • 2019-12-12
        • 2016-03-12
        • 2021-11-26
        • 1970-01-01
        • 2020-02-29
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多