2017-09-25 43 views
0

我使用我的自定义SurfaceView来显示相机预览,并且有一些UI元素浮在SurfaceView上,例如用于拍照的按钮。但有时SurfaceView会出现在顶层出于某些未知的原因,我看不到任何UI元素,但仍然可以与它们进行交互。为什么?我在底层指定了我的自定义SurfaceView,但有时出现在顶层。为什么?

+0

发表您的XML代码 –

+0

也许这将有助于显示的代码您的自定义SurfaceView。从头顶开始,我只能想到setZOrderOnTop https://developer.android.com/reference/android/view/SurfaceView.html#setZOrderOnTop(boolean)。但是你可能会知道你正在使用它。 –

回答

0

您需要了解的android:layout_weight例如

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:weightSum="2" 
    android:orientation="vertical"> 

<LinearLayout 
    android:id="@+id/layoutParent" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1.7" 
    android:orientation="vertical"> 

    // Write xml code for camera display 
</LinearLayout> 

<LinearLayout 
    android:id="@+id/layoutParent" 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="0.3" 
    android:orientation="horizontal"> 
    <Button 
     android:id="@+id/Save" 
     android:text="Save" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
    <Button 
     android:id="@+id/Cancel" 
     android:text="Cancel" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"/> 
</LinearLayout> 
</LinearLayout> 

我希望它会帮助你..

相关问题