Android按钮未显示在SurfaceView顶部

Android按钮未显示在SurfaceView顶部,android,android-layout,button,surfaceview,Android,Android Layout,Button,Surfaceview,因此,在一个活动中,我有一个SurfaceView,用作绘图画布,还有两个布局来提供UI功能。有一个LinearLayout按钮和一个RelativeLayout,我稍后会用到它(它从一开始就消失了,后来被称为VISIBLE) 现在按钮行在屏幕上显示不正确。所有的按钮都被洗掉了,就好像它们被困在画布后面一样。我已尝试将alpha设置为: button.getBackground().setAlpha(255); 我曾尝试使SurfaceView像中一样透明,但这两种方法都不起作用 有趣的是,

因此,在一个活动中,我有一个SurfaceView,用作绘图画布,还有两个布局来提供UI功能。有一个LinearLayout按钮和一个RelativeLayout,我稍后会用到它(它从一开始就消失了,后来被称为VISIBLE)

现在按钮行在屏幕上显示不正确。所有的按钮都被洗掉了,就好像它们被困在画布后面一样。我已尝试将alpha设置为:

 button.getBackground().setAlpha(255);
我曾尝试使SurfaceView像中一样透明,但这两种方法都不起作用

有趣的是,如果我将按钮的背景设置为#ff000000(从下面的一些按钮中可以看出,我一直在测试一些想法),那么它在画布上看起来完全是黑色的,尽管很明显它现在已经失去了按钮形状,这不是我想要的

布局如下:

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/TopLevelView"
android:layout_width="fill_parent"
android:layout_height="fill_parent">

<!--  Drawing Surface -->
<stu.test.project.DrawingSurface
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:id="@+id/drawingSurface"/>

<!--  Button Row -->
<LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:id="@+id/ButtonRow">
        <!--  START BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Start"
            android:visibility="gone"
            android:id="@+id/startDrawingButtonId"/>
        <!--  FINISH BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Finish"
            android:visibility="gone"
            android:id="@+id/finishButtonId"/>
        <!--  RESET BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="#ff000000"
            android:text="Restart"
            android:visibility="gone"
            android:id="@+id/resetButtonId"/>
        <!--  HOME BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Home"
            android:background="#ff000000"
            android:visibility="gone"
            android:id="@+id/homeButtonId"/>
        <!--  RESTART BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Restart"
            android:background="#ff000000"
            android:visibility="gone"
            android:id="@+id/restartButtonId"/>
        <!--  SAVE BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Save"
            android:background="#ff000000"
            android:visibility="gone"
            android:id="@+id/saveButtonId"/>
        <!--  STATS BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Stats"
            android:visibility="gone"
            android:id="@+id/statsButtonId"/>
        <!--  EMAIL BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Send email"
            android:visibility="gone"
            android:background="#ff000000"
            android:id="@+id/emailButtonId"/>
        <!--  LOAD BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Load another record"
            android:visibility="gone"
            android:background="#ff000000"
            android:id="@+id/loadButtonId"/>
        <!--  MARKS BUTTON -->
        <Button
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Add marks"
            android:visibility="gone"
            android:id="@+id/marksButtonId"/>       
</LinearLayout>

<!--  Here is the Marking Scheme Layout -->
<RelativeLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:visibility="gone"
    android:background="@drawable/marks_background"
    android:id="@+id/marksRelativeLayout">
    <!--  Element Title -->
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:id="@+id/markTitle"
        android:padding="10dp"/>
    <!--  Instructions -->
     <TextView
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:text="Enter the score"
         android:id="@+id/markDescription"
         android:padding="10dp"
         android:layout_centerHorizontal="true"
         android:layout_below="@id/markTitle"/>
     <!--  Previous Button -->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Previous"
        android:id="@+id/previousMarkButton"
        android:layout_below="@id/markDescription"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="10dp"/>
    <!--  Marking Scheme -->
    <RadioGroup
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:padding="10dp"
        android:layout_below="@id/markDescription"
        android:layout_toRightOf="@id/previousMarkButton"
        android:id="@+id/marksRadioGroup">
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="0"
            android:id="@+id/radioButton0"/>
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="1"
            android:id="@+id/radioButton1"/>
        <RadioButton 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="2"
            android:id="@+id/radioButton2"/>
    </RadioGroup>
    <!-- Next Button -->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Next"
        android:id="@+id/nextMarkButton"
        android:layout_below="@id/markDescription"
        android:layout_marginRight="10dp"
        android:layout_toRightOf="@id/marksRadioGroup"/>
    <!--  Done Button -->
    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Done"
        android:id="@+id/doneMarkButton"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="10dp"
        android:layout_below="@id/marksRadioGroup"/>
</RelativeLayout>

</FrameLayout>

这是一张图片:

如果您希望“按钮行”位于布局顶部,只需在线性布局处添加:

android:layout_gravity="bottom"
默认情况下,添加到FrameLayout堆栈的视图


看到你的布局,我也注意到所有按钮的可见性都消失了。要检查行是否位于表面视图的顶部,请在按钮行线性布局中添加背景。

您的问题与Android 3.0+上Holo主题中使用的默认图像有关;看一看,这是该主题中默认按钮实际使用的9补丁。请注意PNG本身是如何部分透明的?这意味着无论你在它下面放什么颜色,它都会部分地通过背景显示出来。它被设计用来覆盖该主题中呈现的黑暗背景

Holo主题中的所有按钮都是部分透明的,即使是Holo.Light中的按钮也是如此,因此您可以在任何默认按钮背景下获得这种效果。因为透明度在背景图像中,所以设置
可绘制
的alpha不会有任何效果。正如您已经发现的,您可以将按钮背景设置为实心,这不再是一个问题

如果您想要一个仍然保持全息外观的实心按钮,我建议您从我提供的链接源中提取PNG图像,并修改9面片,使其具有完全纯色的参考底图


HTH

SurfaceView.setZOrderOnTop(假);希望这能对你有所帮助

我在帖子中添加了几张图片来展示它的样子。该行绝对是可查看的,请参见第二张图片,我将background=“#ffff0000”置于此处进行测试。就像我说的,如果我将按钮的背景设置为纯色,它们显示的很好,只是当背景是默认的按钮图像时,出现了一个问题,我明白了,问题是默认的按钮在正常状态下有一个透明的背景。您可以尝试为按钮设置另一个背景。例如,在android sdk安装目录中搜索:android-sdk-mac_86/platforms/android-15/data/res/drawable xhdpi/btn_default_normal_holo_dark.9.png并将所有资源复制到项目中,同时添加位于以下位置的选择器:android-sdk-mac_86/platforms/android-15/data/res/drawable/btn_default_holo_dark.xml。尝试不同的组合。例如,不要使用btn_default_normal_holo_dark,而是使用另一个btn_normal_holo_dark作为正常状态。
false
是默认值,因此这没有区别。