2013-10-11 1 views
0

RelativeLayout에서 5 개의보기 (위, 아래, 왼쪽, 오른쪽, 가운데)로 다음 결과를 얻은 다음 카메라 미리보기를 배치합니다. 나는 또한 원하는 무엇안드로이드 경계선 주위의보기가 작동하지 않습니다.

camera preview

중심보기 주위에 테두리를 그릴 것입니다. 나는 그것을 위해 shape drawable을 사용했다. 그러나 그것은 작동하지 않았다. 테두리는 중심을 제외한 상대적인 레이아웃의 모든 뷰에 적용됩니다.

어떻게 테두리를 그릴 수 있습니까? 여기

레이아웃입니다 :

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

    <RelativeLayout 
     android:id="@+id/camera_preview" 
     android:layout_width="fill_parent" 
     android:layout_height="0dp" 
     android:layout_gravity="center" 
     android:layout_weight="1" > 

     <View 
      android:id="@+id/top" 
      android:layout_width="match_parent" 
      android:layout_height="180dp" 
      android:layout_alignParentTop="true" 
      android:layout_gravity="center" 
      android:background="#80000000" /> 

     <View 
      android:id="@+id/bottom" 
      android:layout_width="match_parent" 
      android:layout_height="180dp" 
      android:layout_alignParentBottom="true" 
      android:layout_gravity="center" 
      android:background="#80000000" /> 

     <View 
      android:id="@+id/left" 
      android:layout_width="100dp" 
      android:layout_height="match_parent" 
      android:layout_above="@id/bottom" 
      android:layout_alignParentLeft="true" 
      android:layout_below="@id/top" 
      android:layout_gravity="center" 
      android:background="#80000000" /> 

     <View 
      android:id="@+id/right" 
      android:layout_width="100dp" 
      android:layout_height="match_parent" 
      android:layout_above="@id/bottom" 
      android:layout_alignParentRight="true" 
      android:layout_below="@id/top" 
      android:layout_gravity="center" 
      android:background="#80000000" /> 

     <View 
      android:id="@+id/center" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_above="@id/bottom" 
      android:layout_below="@id/top" 
      android:layout_gravity="center" 
      android:layout_margin="25dp" 
      android:layout_toLeftOf="@+id/left" 
      android:layout_toRightOf="@id/right" 
      android:background="@drawable/border_red" /> 

    </RelativeLayout> 

    <Button 
     android:id="@+id/button_capture" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_gravity="center" 
     android:text="Capture" /> 

</LinearLayout> 

여기에 border_red.xml입니다 : 당신이에 맞게 너무 많이했다 View에 마진을 제공하고 있기 때문에

<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
    <solid android:color="#00000000"/> 
    <padding android:left="10dp" android:top="10dp" 
     android:right="10dp" android:bottom="10dp" /> 
    <stroke android:color="#FF0000" android:width="5dp" /> 
</shape> 

답변

2

입니다 귀하의 센터 View을 볼 수 없었던 이유입니다. 귀하의 센터 View 아래에 View 코드로 교체하십시오. 나를 위해, 그것이 당신을 위해 작동 희망도 예.

<View 
     android:id="@+id/center" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_above="@id/bottom" 
     android:layout_below="@id/top" 
     android:layout_gravity="center" 
     android:layout_toLeftOf="@+id/right" 
     android:layout_toRightOf="@+id/left" 
     android:background="@drawable/border_red" /> 
+0

작동하지 않았습니다. match_parent는 제가 생각한 높이 값입니다. –

+0

좋아요, 제 대답을 편집했습니다. 시도하십시오 이제 작동 할 것입니다. – Manishika

+0

이제 작동했습니다. 감사. –

0

대안 솔루션 : -

 <LinearLayout 
     android:id="@+id/center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_above="@id/bottom" 
     android:layout_below="@id/top" 
     android:layout_gravity="center" 
     android:layout_margin="25dp" 
     android:layout_toLeftOf="@+id/left" 
     android:layout_toRightOf="@id/right" 
     android:background="#FF0000" 
     android:padding="5dp"> 

     <View 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:background="#00000000"/> 
     </LinearLayout> 
+0

작동하지 않았습니다. –

+0

오 ... !! 카메라 미리보기를'보기 '에두면 확실히 작동 할 것입니다. 예를 들어,'보기'라는 자식을 추가해야합니다. –

+0

카메라 미리보기가 전체 RelativeLayout에 배치됩니다. 중심보기는 쓸모가 없다. 국경을 표시하기 위해 추가했습니다. –

0

View

수평 라인이 android:layout_height="5dp" 같은 5dp

<View 
    android:id="@+id/view" 
    android:background="#FF4500" 
    android:layout_width="fill_parent" 
    android:layout_height="2dp"  
    android:layout_below="@+id/listview_id" /> 

수직선

,369을 높이 감소
<View 
    android:id="@+id/view" 
    android:background="#FF4500" 
    android:layout_width="2dp" 
    android:layout_height="fill_parent"  /> 
+0

이것은 내가하려는 일과 관련이 없습니다. –