【问题标题】:Add opaque button over the surfaceview在表面视图上添加不透明按钮
【发布时间】:2015-02-25 08:34:49
【问题描述】:

在我的应用程序中,我想实现一个应该包含一些按钮的屏幕,并且作为屏幕的背景,我想要一个显示一些动画的表面视图。为此,我扩展了显示动画的表面视图。我面临的问题是,当我添加一些按钮时,它们并不是完全不透明的。它们保持透明,我可以通过它们看到背景动画。我尝试将按钮的背景颜色设置为#FF000000,但它仍然不是完全不透明的。

这是我的 activity_main.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/bg_view"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

        <com.myproj.example.widgets.CustomSurfaceView
            android:id="@+id/surface_view"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" >

            <Button
                android:id="@+id/test_button"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:background="#FF000000"
                android:text="Should be Opaque" />
        </RelativeLayout>
    </FrameLayout>

</RelativeLayout>

我试过Android:How to add a button in surface viewRendering a button over SurfaceView, 但是按钮仍然不是不透明的。

【问题讨论】:

  • 在玩 Grafika 时,我发现某些主题具有部分透明的 UI 元素。如果我切换到android:theme="@android:style/Theme.NoTitleBar.Fullscreen",小部件就会失去透明度。
  • 你解决了吗?我问了一个类似的问题。 stackoverflow.com/questions/29266322/…

标签: android surfaceview


【解决方案1】:

尝试添加一个不透明的“Drawable”作为按钮的背景。

【讨论】:

  • 尝试了this 的裁剪版本。还是透明的。
【解决方案2】:

使用背景颜色作为#80000000 -

 <Button
            android:id="@+id/test_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="#80000000"
            android:text="Should be Opaque" />

【讨论】:

    猜你喜欢
    • 2015-04-18
    • 1970-01-01
    • 2014-11-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-12
    • 2019-09-21
    相关资源
    最近更新 更多