2012-01-05 5 views
1

다음 예와 같이 I는, 상기 상하 각각 4 ImageView를 사용하여 프레임을 남겨 그 프레임의 오른쪽을 설계하고자 :Android에서 프레임을 디자인하는 방법은 무엇입니까?

enter image description here

간단 보이지만 내가 정말 힘든 시간을 보내고. 나는 다음과 같은 layout_alignParentLeft|Right|Top|Bottom와 함께 FrameLayout를 사용하여 시도 : 그것은 위쪽의 오른쪽과 아래쪽을 배치 같은

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/camera_masque" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    > 
     <ImageView 
      android:id="@+id/camera_top_masque" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_top_masque_photo" 
      android:layout_alignParentTop="true" 
     /> 

     <ImageView 
      android:id="@+id/camera_left_masque" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:src="@drawable/ic_left_masque_photo" 
      android:layout_alignParentLeft="true" 
     /> 

     <ImageView 
      android:id="@+id/camera_right_masque" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:src="@drawable/ic_right_masque_photo" 
      android:layout_alignParentRight="true" 
     /> 

     <ImageView 
      android:id="@+id/camera_bottom_masque" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_bottom_masque_photo" 
      android:layout_alignParentBottom="true" 
     /> 
</FrameLayout> 

이 (다른 사람을 위해 상단과 왼쪽 측면에서 잘 작동,하지만 ...).

나는이 같은 RelativeLayout를 사용하여 시도 : 예상대로

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/camera_masque" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="#FFFFFF" 
    > 
     <ImageView 
      android:id="@+id/camera_top_masque" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_top_masque_photo" 
      android:layout_alignParentTop="true" 
     /> 

     <ImageView 
      android:id="@+id/camera_left_masque" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:layout_marginLeft="-2dp" 
      android:src="@drawable/ic_left_masque_photo" 
      android:layout_below="@id/camera_top_masque" 
     /> 

     <ImageView 
      android:id="@+id/camera_right_masque" 
      android:layout_width="wrap_content" 
      android:layout_height="match_parent" 
      android:src="@drawable/ic_right_masque_photo" 
      android:layout_marginRight="-2dp" 
      android:layout_below="@id/camera_top_masque" 
      android:layout_alignParentRight="true" 
     /> 

     <ImageView 
      android:id="@+id/camera_bottom_masque" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:src="@drawable/ic_bottom_masque_photo" 
      android:layout_alignParentBottom="true" 
     /> 
</RelativeLayout> 

그러나 같은 일이 작동하지 않습니다.

내 레이아웃에 어떤 문제가 있습니까? 내가 어떻게 이걸 이룰 수 있니?

참고 : 이미지 크기는 640 * 114px (상단, 하단) 및 34 * 572 (왼쪽, 오른쪽)입니다.

감사합니다.

답변

4

나는 보통 이런 식으로 linearlayout을 사용하고 layout_weight 매개 변수를 사용하여 채우기를 제어합니다. 아마도 비슷한 질문을 많이 찾을 것입니다.

세로 선형 레이아웃을 만들고 중간 섹션에 가로 선형 레이아웃을 만듭니다. 이클립스의 ADT에서 WYSIWYG 레이아웃 디자이너를 사용하는 경우

이 자세한

에 대한 tools.android.com .see ... 훨씬 간단하게 구성되어

스택으로 더 유용한 자원이다 안드로이드 레이아웃을 사용할 수 자습서 많이 있습니다 오버플로는 레이아웃보다는 프로그래밍 문제를 처리하는 경향이 있습니다.

+0

2 'LinearLayout'을 사용하는 것보다 효율적이기 때문에 'RelativeLayout'을 사용하겠습니다. ADT에서 WYSIWYG 도구를 사용하는 것이 좋습니다. 내 실수를 찾는데 도움이되었습니다. 오른쪽과 왼쪽의'ImageView'에'alignParentTop'을 추가하고 맨 아래의'ImageView'에'alignParentLeft'를 추가해야했습니다. 나는이 뒤에있는 논리를 이해하지 못한다 ... –

+0

[레이아웃 트릭 효율] (http://developer.android.com/resources/articles/layout-tricks-efficiency.html)을 말하는 경우에는 아마 받아 들일 만하다. 이 경우에는 선형을 중간 행으로하여 상대를 사용하여 혼합하고 일치시킬 수 있습니다. 때로는 레이아웃이 어떻게 작동 하는지를 아는 것이 효율성보다 중요합니다. 더 복잡한 레이아웃과 목록 항목을 디자인 할 때주의해야합니다. – Merlin

+0

예 저는이 기사를 언급했습니다. 두 번째 요점에 동의! –

1

제가 실수 한 것을 강조하기 위해 제 질문에 답변 해 드리겠습니다. 밝혀졌지만, 나는 거의 거기에 있었고, 나는 ImageViewalignParentLeftImageViewalignParentTop을 추가해야했다.

나는 이것의 뒤에 논리를 이해하지 않는다! (누군가 설명 할 수있는 경우 ...)

1

프레임이 동일한 이미지로 작성된 경우. 9-patch drawable 또는 테두리가있는 투명한 중심을 사용해보십시오.

+0

실제로 두 개의 이미지가 있습니다. 그 외에 좋은 생각이야. –

관련 문제