내 서브 클래스 Dialog
을 사용하여 화면을 채울 수있는 내용이 충분하지 않으면 내용에 맞게 축소되도록 즉 wrap_content
). (중요하지 않습니다 - - 내가 생각 나는 비트를 삭제했습니다)사용자 지정 대화 상자의 ListView를 사용하면 화면에서 단추가 누락됩니다.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg">
<RelativeLayout
android:id="@+id/title_container"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:background="@drawable/dialog_title_bg">
. . .
</RelativeLayout>
<LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/content"
android:orientation="horizontal">
. . .
</LinearLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_container">
</FrameLayout>
</RelativeLayout>
: 나는 다음과 같은 레이아웃이 작업을 수행 할 수 있습니다. 내용이 화면에 기입하지 않는 경우가 잘 작동 :
그러나이 내용이 큰 경우, 그것은 아래 떨어져있는 버튼을 밀어 :
약간의 조정, 나는 button_container
변경 그래서 layout_alignParentBottom="true"
을 가지고와 content
은과 같이, 그것은 위 입니다 :
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/dialog_bg">
<RelativeLayout
android:id="@+id/title_container"
android:layout_width="match_parent"
android:layout_height="60dp"
android:gravity="center_vertical"
android:background="@drawable/dialog_title_bg">
. . .
</RelativeLayout>
<LinearLayout
android:id="@+id/button_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
. . .
</LinearLayout>
<FrameLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/title_container"
android:layout_above="@+id/button_container">
</FrameLayout>
</RelativeLayout>
는 지금은 내용이 너무 커서 스크린 때 작동 :
그러나 내용이 화면을 채울하지 않는 경우, 대화 상자가 여전히 수행합니다
어떻게하면 두 세계에서 최고의 가치를 얻을 수 있습니까? 아마도 "maxHeight"를 화면의 높이에서 대화 상자 테두리와 제목 및 버튼의 높이를 뺀 값으로 설정하여 코드에서 수행 할 수 있습니다. 그러나 이는 나에게 조금 해킹 된 것처럼 보입니다. AlertDialog (이 상황을 올바르게 처리하는 것처럼 보입니다)의 구현을 살펴 보았지만 나에게 마술처럼 보였습니다 ...
편집 : 요청에 따라 여기에 추가 한 레이아웃 파일의 내용입니다. 대신 프레임 레이아웃의
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ListView
android:id="@+id/report_items"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
</RelativeLayout>
혹시 이것에 대한 해결책을 찾았습니까? 나는 똑같은 경험을하고있다. –
@StuartRobertson 불행히도 아니, 결국 나는 질문에서 언급 한 'maxHeight'를 사용하여 코드에서이를 수행했다. –