2011-09-27 70 views
2

我想知道是否有某種方法可以讓相機預覽填充屏幕的一部分,並且在底部有一個textview框供我稍後添加文本。 我還沒有任何代碼,因爲在繼續執行代碼之前,我的團隊仍在評估這是否可行。是否可以在相同的屏幕上顯示Camera Preview和TextView?

編輯2:現在我終於能夠在玩android:gravity之後看到屏幕上的文字。但是TextView總是顯示在屏幕的頂部,有什麼方法可以將它移動到底部?

編輯3:改變機器人:layout_height到FILL_PARENT代替WRAP_CONTENT固定的定位問題

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent"> 
     <SurfaceView android:id="@+id/preview_view" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_centerInParent="true"/> 
     <com.google.zxing.client.android.ViewfinderView 
      android:id="@+id/viewfinder_view" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:background="@color/transparent"/> 
     ........ 
     ........ 
     <TextView android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:gravity="bottom" 
      android:text="Header text"/> 

</FrameLayout> 

回答

2

是的,這是可能的。你應該使用FrameLayout這個。這裏有一個例子:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

    <SurfaceView android:id="@+id/preview_view" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:layout_centerInParent="true"/> 

    <TextView android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:gravity="top|center_horizontal" 
      android:text="Header text"/> 

</FrameLayout> 
+0

感謝您的回答,我應該提到的是,我發現了攝像頭預覽實際上是從斑馬線的條碼掃描器延長。我想減少相機預覽尺寸,並在底部有一個Textview。我嘗試添加TextView作爲你們兩個人的建議,但我無法看到任何區別。爲了您的參考,我將附上zxing xml文件 –

+0

它現在可以使用!但是有一個小問題,我編輯了我的帖子以包含我正在處理的代碼。重力似乎不能正常工作:/我需要線性佈局嗎? –

+0

您使用了'android:layout_height =「wrap_content」',而它應該是'fill_parent'來表示水平重力以使感覺/工作。 – inazaruk

1

是有可能是這樣的:

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

    <android.view.SurfaceView 
    android:id="@+id/surface" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" /> 

<TextView 
    android:id = "@+id/txtview" 
    android:layout_width = "wrap_content" 
    android:layout_height = "wrap_content" 
    android:text = "TextView" 
    android:padding = "7dp" 
    android:gravity = "bottom" /> 

</FrameLayout> 
+0

有沒有什麼辦法可以將兩個答案都設置爲接受。我只能設置一個答案。 感謝您的幫助,我現在有點工作了,但我無法將textview的位置更改爲底部..它始終顯示在頂部。有小費嗎? –

+0

沒關係,我認爲你得到了你問的解決方案....乾杯.... –

相關問題