【问题标题】:Android make part of activity transparentAndroid使部分活动透明
【发布时间】:2013-02-12 05:07:19
【问题描述】:

我有以下布局:

<RelativeLayout>
   <TextView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:text="@string/hello_world" />

    <LinearLayout
      android:layout_width="fill_parent"
      android:layout_height="200dip"
      android:layout_alignParentBottom="true" >
    </LinearLayout>
</RelativeLayout>

我想让线性布局完全透明,也就是说,活动堆栈上前一个活动的内容应该在线性布局区域中可见。

我尝试过将 setAlpha(0) 与线性布局一起使用;它确实使它透明,但它在线性布局区域中显示活动背景颜色。

我也尝试将活动的 android:theme 设置为 @android:style/Theme.Translucent.NoTitleBar,但这会使整个活动显示上一个活动的内容。

谁能推荐一个方法?

谢谢。

【问题讨论】:

    标签: android android-activity transparency


    【解决方案1】:

    需要明确的是,活动不是可见的对象。视图是您在屏幕上看到的——特别是您看到附加到您的活动的视图。在这种情况下,该视图是 RelativeLayout 及其内容。

    当你让LinearLayout透明时,它会显示RelativeLayout的背景颜色。如果您想查看相对布局背后的内容,请将其背景颜色也设为透明。

    <RelativeLayout android:backgrond="#00000000"> 
           ... 
          <LinearLayout android::background="#00000000"> 
               ... 
          </LinearLayout>
     </RelativeLayout>
    

    当然,您可能想要使用命名颜色资源而不是“#00000000”

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-29
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多