我想知道是否有某種方法可以讓相機預覽填充屏幕的一部分,並且在底部有一個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>
感謝您的回答,我應該提到的是,我發現了攝像頭預覽實際上是從斑馬線的條碼掃描器延長。我想減少相機預覽尺寸,並在底部有一個Textview。我嘗試添加TextView作爲你們兩個人的建議,但我無法看到任何區別。爲了您的參考,我將附上zxing xml文件 –
它現在可以使用!但是有一個小問題,我編輯了我的帖子以包含我正在處理的代碼。重力似乎不能正常工作:/我需要線性佈局嗎? –
您使用了'android:layout_height =「wrap_content」',而它應該是'fill_parent'來表示水平重力以使感覺/工作。 – inazaruk