2011-09-27 2 views
2

카메라 미리보기에 화면의 일부를 채우는 방법이 있는지 궁금 해서요. 하단에는 나중에 텍스트를 추가 할 수있는 텍스트보기 상자가 있습니다. 코드를 계속 진행하기 전에 팀에서 아직이 기능을 사용할 수 있는지 평가 중이므로 아직 코드가 없습니다.Camera Preview와 TextView를 같은 화면에 둘 수 있습니까?

편집 2 : 이제 마침내 안드로이드 : 중력을 가지고 놀고 나면 화면의 텍스트를 볼 수있게되었습니다. 그러나 TextView는 항상 화면 상단에 나타나며, 아래쪽으로 옮길 수있는 방법이 있습니까?

편집 3 : 안드로이드 변경 : 대신 wrap_content의 fill_parent하는 layout_height은 위치 문제

<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

감사합니다, 나는 내가 갖는 카메라 미리보기가 실제로 Zxing의 바코드 스캐너에서 연장되는 것을 언급 한 것이다. 나는 카메라 미리보기 크기를 줄이고, 아래쪽에 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

두 대답을 합격으로 설정할 수있는 방법이 있습니까? 하나만 설정할 수 있습니다. 도움을 주셔서 감사합니다. 지금은 다소 효과가 있습니다 만, 텍스트 뷰의 위치를 ​​아래쪽으로 변경할 수 없습니다. 항상 맨 위에 표시됩니다. 어떤 팁? –

+0

그건 괜찮아요, 당신이 해결책을 찾은 것 같아요. 건배 .... –

관련 문제