2012-10-03 241 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内容。