2016-08-04 53 views
0

我的Android XML的布局看起来像这样如何创建Android的XML-布局的通透查看

<?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孔的大小我的小观点。像下面的图片:

enter image description here

这可能吗?怎么样?

+0

请考虑标记答案和/或提高答案。 – EJoshuaS

+0

@Marcel你有没有找到解决方案? –

+0

不,我不这么认为 – Marcel

回答

1

使用透明背景在你想透明的意见,如果有它背后的任何视图就会显示

如:

android:background="#00000000" 
  • 普通不透明的黑色六角形“#000000”
  • 完全透明的 - “#00000000”
  • 完全不透明 - “#FF000000”
  • 50%transpa出租 - “#8000”
+0

,但它必须经过unterlying布局,并显示这背后是什么。看看图片。 – Marcel

+0

父母之一,红色的小孩在它可以说一个相对的(白色的),它在中间,在另一个布局是透明的,所以它符合您的要求 –

0

如果您希望为视图的通透的背景下,什么都可以做的是: -

  • 布局1:取父布局填充背景 - 机器人:layout_width =“match_parent”android:layout_height =“match_parent”:说红色
  • 布局2:现在采取另一种布局填充任何大小的屏幕是必要的:说蓝色
  • 查看:您可以将您的视图[在这个布局和layout_width = 20px,layout_height = 20px和背景colo中看穿r应该与红色的Layout1相同。这现在看起来像蓝色背景中的透视孔。

希望这可以帮助。

例子:

<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

林相当肯定你会看到通过这个蓝色的背景。任何示例? – Marcel

+0

我已经添加了代码片段,它将向您显示蓝色背景上的红色透明视图。 – Neh

+0

但是如果底部LL有背景图像,我想在顶部视图中看到这部分内容? – Marcel

0

查找Alpha通道 - 我认为这基本上是你在找什么在这里。