나는 내 인생을 감당할 수 없다.Android 레이아웃 문제
이미지 뷰 (충전 가능한 모든 공간) 텍스트 뷰 글고 치기가
(등 간격) 버튼 버튼 버튼 (수직 필요에 따라 공간을 복용) (필요에 따라 수직 공간을 복용) : 나는 (수직) 다음과 같은 레이아웃을 시도하고있다다음 레이아웃을 설정했습니다. 이미지보기는 현재 200dip으로 설정되어 있습니다. 사용 가능한 모든 공간을 채우기 위해이 값은 무엇이되어야합니까? 다른 구성 요소가 먼저 와야하고 이미지보기는 남아있는 것을 가져와야합니다. 나는 이것에 대한 예를 찾고 아직 아무것도 찾지 못했다. 당신이 필요로하는 모든이 남은 공간을 취할 수있는 ImageView
에 적절한 무게와 LinearLayout
처럼
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView android:id="@+id/imgView"
android:layout_width="fill_parent"
android:layout_height="200dip"
android:layout_alignParentTop="true" />
<TextView android:id="@+id/lblDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/PhotoDesc"
android:layout_below="@id/imgView" />
<EditText android:id="@+id/edtDesc"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lblDesc" />
<!-- Bottom layout contains the three buttons - Take Photos, Transmit, and Setup. -->
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:weightSum="3">
<!-- Take photos button -->
<Button android:id="@+id/btnCamera"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/TakePhotos" />
<!-- Transmit button -->
<Button android:id="@+id/btnUpload"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="@string/Upload" />
<!-- Setup button -->
<Button android:id="@+id/btnSetup"
android:gravity="center_vertical|center_horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/Setup"
android:layout_weight="1" />
</LinearLayout>
</RelativeLayout>
굉장한 답변 2 회! 둘 다 맞지만 레이아웃 간격이 어떻게 나누어 지는지에 대한 간단한 설명이 매우 유용했습니다. 나는 안드로이드 개발의 날 2에 있고 나는 그것을 얻지 못하고 있었다! 감사! – Paul
두 가지 추가 세부 정보로 답을 혼란스럽게하고 싶지는 않았지만 추가 정보가 마음에 들었으므로 여기에 또 다른 흥미로운 팁이 있습니다. LinearLayout의 자식과 함께 0dip/weight 기술을 사용하면 해당 자식에 대한 초기 측정 패스를 건너 뛰고 중량 측정 통과에만 의존합니다. (체중이없는 어린이들도 한 번만의 패스에 의존합니다.) 자녀가 실제로 측정 시간이 걸리는 복잡한 하위 계층 인 경우 중요한 최적화가 될 수 있습니다. – adamp