2016-08-04 69 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通道 - 我認爲這基本上是你在找什麼在這裏。