2017-09-25 40 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> 

我希望它會幫助你..

相關問題