因此,在一个活动中,我有一个用作画布的SurfaceView,以及两个用于提供UI功能的布局。有一个保存按钮的LinearLayout和一个我稍后会用到的RelativeLayout (它从一开始就消失了,后来调用为VISIBLE )。
现在按钮行不能正确显示在屏幕上。按钮都被冲掉了,就像它们被困在画布后面一样。我尝试使用以下命令设置alpha:
button.getBackground().setAlpha(255);我尝试过像在how to make surfaceview transparent中那样让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>这是一张图片:


发布于 2012-05-12 01:30:04
你的问题与Android 3.0+上的全息主题中使用的默认图像有关;看看at this link,这是该主题中用于默认按钮的实际9补丁。注意到PNG本身是部分透明的吗?这意味着无论你在它下面放置什么颜色,它都会部分地透过它的背景显示出来。它被设计用于在该主题中存在的黑色背景的顶部使用。
全息主题中的所有按钮都是部分透明的,即使是Holo.Light中的按钮也是如此,因此您将在任何默认按钮背景下获得此效果。因为透明度在背景图像中,所以设置Drawable的alpha不会有任何效果。正如您已经发现的,您可以将按钮背景设置为实心,这不再是问题。
如果你想要一个仍然保持全息外观的实心按钮,我建议从我给出的链接源中拉出PNG图像,并修改9补丁,使其具有完全纯色的参考底图。
HTH
发布于 2012-05-11 22:31:52
如果你想把“按钮行”放在布局的顶部,只需在LinearLayout中添加:
android:layout_gravity="bottom"默认情况下,添加到FrameLayout堆栈的视图。
看到你的布局,我也注意到所有按钮的可见性都消失了。若要检查该行是否位于surfaceView顶部,请向按钮行LinearLayout添加背景。
发布于 2014-07-26 12:08:42
SurfaceView.setZOrderOnTop(False);希望这能对您有所帮助
https://stackoverflow.com/questions/10551850
复制相似问题