2011-02-08 4 views
2

android : theme = "@ android : style/Theme.Dialog"와 함께 활동을 사용하여 대화 상자로 사용합니다. 네이티브 대화 상자의 동작에 가장 가까운 것은 무엇입니까 : 대화 상자가 화면 너비에 맞게 채워야합니까? 예를 들어 입력란에 텍스트 상자가 채워져 있으면 동적으로 커야합니까?Android : 대화 상자 너비는 어떻게해야합니까?

내 직감은 대화 상자가 화면을 채우지 않아야한다는 것입니다. 이 동작을 얻으려고했지만, 안드로이드 2.2에서 무엇을해도 대화 상자 폭 은 부모을 채우는 것으로 보입니다.

내 레이아웃 XML은 :

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" android:layout_height="wrap_content" 
    android:orientation="vertical"> 

    <TextView android:id="@+id/text" android:layout_width="fill_parent" 
     android:layout_height="wrap_content" android:autoText="true" 
     android:text="@string/item_delete_dialog_label" 
     android:padding="5dip" /> 

    <LinearLayout android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     style="@android:style/ButtonBar" android:layout_width="fill_parent"> 

     <Button android:id="@+id/yes" android:layout_height="wrap_content" 
      android:text="@string/button_yes" 
      android:layout_width="wrap_content" 
      android:layout_weight="1"/> 

     <Button android:id="@+id/no" android:layout_height="wrap_content" 
      android:text="@string/button_no" 
      android:layout_width="wrap_content" 
      android:layout_weight="1"/> 

    </LinearLayout> 
</LinearLayout> 

나는 많은 대화가 폭 화면을 채우기 만들기에 관한 질문, 그러나 폭 포장 만들기에 대한 없음을 발견했습니다. 이것을 어떻게 얻을 수 있습니까?

답변

0

ButtonBar 스타일은 대화 상자를 표준 단추를 사용할 때보 다 훨씬 넓게 만듭니다. LinearLayout 너비를 wrap_content로 변경하면 대화 상자의 너비가 wrap_content로 설정된 기본 LinearLayout 컨테이너를 채우고 있기 때문에 대화 상자의 너비에 영향을 미치지 않습니다. 버튼 스타일을 변경하면 가장 큰 차이가 있습니다.

0

대화 상자의 일반적인 스타일은 자녀를 감싸는 데 필요한만큼 커야합니다. 자녀가 너비 전체를 차지하지 않으면 대화 상자도 표시되지 않습니다.

LinearLayout의 너비가 fill_parent 인 것이 문제 일 수 있습니다. 이는 허용되는만큼의 공간을 차지할 것임을 의미합니다. wrap_content 너비를 변경하여 필요한 것보다 더 많은 공간을 차지하지 않도록하십시오.

대화 상자가 정말 간단하면 AlertDialog을 사용하십시오.

관련 문제