首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android XML-Layout中创建透明视图

如何在Android XML-Layout中创建透明视图
EN

Stack Overflow用户
提问于 2016-08-04 18:30:33
回答 3查看 1.2K关注 0票数 2

我的Android XML布局如下所示

代码语言:javascript
复制
<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout 
          xmlns:android="http://schemas.android.com/apk/res/android"
          android:orientation="vertical"
          android:gravity="center"
          android:background="?android:colorBackground"
          android:layout_width="match_parent"
          android:layout_height="match_parent">

        <SomeView
            android:layout_width="20dp"
            android:layout_height="20dp"
            android:background="@android:color/transparent"/>


    </LinearLayout>

我需要的是在我的小视图大小的背景LinearLayout中有一个‘透明’的洞。如下图所示:

这个是可能的吗?多么?

EN

回答 3

Stack Overflow用户

发布于 2016-08-04 18:39:04

在要使其透明的视图中使用透明背景,以便在其后面有任何视图时将其显示

例如:

代码语言:javascript
复制
 android:background="#00000000"

"#00000000"

  • Fully

  • 正常不透明黑色十六进制- "#000000“

  • 完全透明-FF000000不透明- "#FF000000”

  • 50%透明- "#80000000"
票数 1
EN

Stack Overflow用户

发布于 2016-08-04 22:01:02

如果您希望该视图具有透明背景,则可以执行以下操作:-

  • Layout 1:采用父布局填充背景:- android:layout_width="match_parent“android:layout_height="match_parent”:表示红色
  • layout 2:现在采用另一个布局填充所需屏幕的大小:例如蓝色
  • 视图:您可以将视图放置在此布局中,并且layout_width=20px,layout_height = 20px和背景颜色应该与Layout1的红色相同。现在,这看起来就像蓝色背景中的一个透明孔。

希望这能有所帮助。

示例:

代码语言:javascript
复制
<LinearLayout
    android:orientation="vertical" android:layout_width="match_parent"
    android:layout_height="match_parent" android:background="@android:color/holo_red_dark">
    <LinearLayout
        android:orientation="vertical"
        android:gravity="center"
        android:background="@android:color/holo_blue_bright"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_margin="30dp">

        <View
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:background="@android:color/holo_red_dark"/>


    </LinearLayout>

</LinearLayout>
票数 0
EN

Stack Overflow用户

发布于 2016-08-04 22:05:38

查找Alpha通道-我认为这基本上就是您在这里寻找的。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38764883

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档