다음 예와 같이 I는, 상기 상하 각각 4 ImageView
를 사용하여 프레임을 남겨 그 프레임의 오른쪽을 설계하고자 :Android에서 프레임을 디자인하는 방법은 무엇입니까?
간단 보이지만 내가 정말 힘든 시간을 보내고. 나는 다음과 같은 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 (왼쪽, 오른쪽)입니다.
감사합니다.
2 'LinearLayout'을 사용하는 것보다 효율적이기 때문에 'RelativeLayout'을 사용하겠습니다. ADT에서 WYSIWYG 도구를 사용하는 것이 좋습니다. 내 실수를 찾는데 도움이되었습니다. 오른쪽과 왼쪽의'ImageView'에'alignParentTop'을 추가하고 맨 아래의'ImageView'에'alignParentLeft'를 추가해야했습니다. 나는이 뒤에있는 논리를 이해하지 못한다 ... –
[레이아웃 트릭 효율] (http://developer.android.com/resources/articles/layout-tricks-efficiency.html)을 말하는 경우에는 아마 받아 들일 만하다. 이 경우에는 선형을 중간 행으로하여 상대를 사용하여 혼합하고 일치시킬 수 있습니다. 때로는 레이아웃이 어떻게 작동 하는지를 아는 것이 효율성보다 중요합니다. 더 복잡한 레이아웃과 목록 항목을 디자인 할 때주의해야합니다. – Merlin
예 저는이 기사를 언급했습니다. 두 번째 요점에 동의! –