2012-10-03 134 views
1

我有一個簡單的佈局(一堆彩色面板)的單一活動,我試圖在頂部的透明視圖上覆蓋一個小的移動圖形。像@umar here我跟着this tutorial但我的覆蓋視圖拒絕透明。我可以讓視圖出現,它只包含它應該的內容,但視圖的背景是黑色的,但是我試圖使它透明失敗。我已經嘗試了一些在SO上提到的解決方案,它總是出來。爲什麼我的'透明'覆蓋視圖不透明?

我的佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/everything" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="vertical" 
android:background="#00ffffff" 
> 

<LinearLayout 
    android:id="@+id/row_1_bg" 
    android:layout_width="fill_parent" 
    android:layout_height="0dip" 
    android:layout_weight="1" 
    android:orientation="horizontal" 
    > 

    <FrameLayout 
     android:layout_height="fill_parent" 
     android:layout_width="100dp" 
     > 

     <LinearLayout 
      android:id="@+id/row_1_table" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:background="#808080" 
      > 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="0dip" 
       android:layout_weight="1" 
       android:orientation="horizontal" 
       > 

      <TextView 
       android:id="@+id/row_1_pantone" 
       android:paddingLeft="6dip" 
       android:textColor="#f0f0f0" 
       android:textStyle="bold" 
       android:gravity="center_vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       > 
      </TextView> 
     </LinearLayout> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:orientation="horizontal" 
      > 
      <TextView 
       android:id="@+id/row_1_rgb" 
       android:paddingLeft="6dip" 
       android:textColor="#f0f0f0" 
       android:textStyle="bold" 
       android:gravity="center_vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       > 
      </TextView> 
     </LinearLayout> 
     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="0dip" 
      android:layout_weight="1" 
      android:orientation="horizontal" 
      > 
      <TextView 
       android:id="@+id/row_1_hex" 
       android:paddingLeft="6dip" 
       android:textColor="#f0f0f0" 
       android:textStyle="bold" 
       android:gravity="center_vertical" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       > 
      </TextView> 
     </LinearLayout> 
    </LinearLayout> 
</FrameLayout> 
</LinearLayout> 

<LinearLayout 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:paddingRight="5px" 
android:paddingTop="5px" 
android:paddingLeft="5px" 
android:gravity="bottom" 
android:orientation="vertical" 
android:background="#00808080"> 

<barry.pantone.TransparentPanel 
     android:layout_height="wrap_content" 
     android:layout_width="fill_parent" 
     android:id="@+id/transparent_panel" 
     android:paddingRight="5px" 
     android:paddingTop="5px" 
     android:paddingLeft="5px" 
     android:paddingBottom="5px" 
     android:background="#00808080"> 

     <Button 
      android:layout_height="wrap_content" 
      android:layout_width="wrap_content" 
      android:id="@+id/button_click_me" 
      android:text="Click Me!" 
      /> 
</barry.pantone.TransparentPanel> 
</LinearLayout> 

</LinearLayout> 

我TransparentPanel.java是直接從本教程中,使用:

innerPaint.setARGB(225, 75, 75, 75); 

做一個透明的面板,這是主要的活動我的onCreate:

public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Resources res = getResources(); 
    sPantone = res.getStringArray(R.array.pantone); // gets colour definitions 

    iHeight = getWindowManager().getDefaultDisplay().getHeight(); 

    PopulateTable(); // draws colours in the various layout elements 
    } 

問題是,無論我在視圖內做什麼都很好 - 我可以繪製一個半透明父視圖在該視圖中的其他元素,但疊加視圖本身具有黑色背景,從而遮蔽了下方的佈局。如果有人能夠幫助我理解透明度爲什麼不起作用,我會永遠感激。

非常感謝

巴茲

編輯

繼另一個想法我試圖移動覆蓋的定義伸到自己的XML文件,並使用LayoutInflater膨脹,並添加新的視圖。不。完全相同 - 附加視圖具有堅實的背景。這裏的tranny.xml佈局:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
android:background="#80000040" 
android:layout_height="fill_parent" 
android:layout_width="fill_parent" 
xmlns:android="http://schemas.android.com/apk/res/android" 
android:paddingRight="5dip" 
android:paddingTop="5dip" 
android:paddingLeft="5dip" 
android:gravity="bottom" 
android:orientation="vertical" 
> 
<Button 
    android:layout_height="wrap_content" 
    android:layout_width="wrap_content" 
    android:id="@+id/button_click_me" 
    android:text="Click Me!" 
    /> 
</LinearLayout> 

,這裏是從的onCreate代碼膨脹的新觀點,並把它添加到主佈局:

private View view; 
ViewGroup parent = (ViewGroup) findViewById(R.id.everything); 
view = LayoutInflater.from(getBaseContext()).inflate(R.layout.tranny, parent, false); 
parent.addView(view); 

基本上,我已經走了究竟創建相同結果使用不同的技術。第一次方便了解LayoutInflater,但沒有幫助重新透明:(

回答

0

好吧,沒有答案,所以我假設沒有辦法使用parent.addView(view)添加一個透明背景的疊加視圖。在我的佈局(滾動條)的右側邊緣添加一個狹窄的透明視圖,在其中我可以繪製一個位圖,指示顯示項目的大列表中的位置。

取而代之,現在我已將整個佈局稍微縮小並留下了一個狹窄的空間LinearLayout右邊緣,它有一個黑色的背景,並進入我畫我的位圖,所以我得到這個:

enter image description here

我寧願把指針放在顏色的塊的頂部,但除非在未來的某個大師發現這個問題,併爲我們展示瞭如何做到這一點,我非常接近。

Baz。

0

我可以在該視圖

正是這個畫在其它元件的半透明面板。你需要「透明度」來覆蓋背後的內容。

透明度可能正常,但父佈局的背景是透明的(#00ffffff),所以疊加層的背景看起來很黑。

更改您的根佈局的背景,您可能會看到透明度正在工作。

如果您希望它覆蓋視圖的其他元素,則需要透明度作爲該佈局的該部分的子元素。它目前的佈局方式是這樣的:

<App> 
    <Content> 
    </Content> 
    <Overlay> 
    </Overlay> 
</App> 

而你需要:

<App> 
    <Content> 
    <Overlay> 
    </Overlay> 
    </Content> 
</App> 

如果你看看來源爲您遵循該教程中,您將看到自定義透明面板是MapView的子項,而不是根應用程序視圖。這就是爲什麼它能夠覆蓋MapView內容。