2016-01-23 68 views
0

我想在相机预览的顶部放置一个imagebutton。 这很简单,除非你想移动按钮。imagebutton上方的相机预览

布局:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" 
android:id="@+id/my_linear_layout" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 
    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
    /> 
    <LinearLayout 
     android:id="@+id/linear" 
     android:layout_width="match_parent" 
     android:layout_height="fill_parent" 
     android:gravity="bottom" 
     android:orientation="vertical" > 

     <ImageButton 
      android:id="@+id/btn" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center"/> 
    </LinearLayout> 
</RelativeLayout> 

如果我把按钮,它工作正常,在屏幕的底部。但是,如果我把按钮放在中间,例如,将它移向底部,它会消失,因为linearLayout不是全屏。

什么是做我想做的最好的方式?感谢的

回答

0

最简单的方法是使用FrameLayout

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

    <FrameLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" /> 

    <ImageButton 
     android:id="@+id/btn" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" /> 
</FrameLayout> 
+0

我有同样的问题与此代码。当我向底部移动时,图像按钮消失 – Eyhze