2011-02-08 10 views
2

私はandroid:theme = "@ android:style/Theme.Dialog"というアクティビティを使ってダイアログとして機能させています。 ネイティブダイアログの動作に最も近いもの:ダイアログが画面に表示されますか(幅)する必要がありますか?たとえば、テキストボックスに「?」と入力して入力した場合、動的に大きくなるはずです。Android:ダイアログの幅はどのようにする必要がありますか?

私の勘違いは、ダイアログが画面いっぱいになってはならないということです。私はこの動作をしようとしましたが、私が何をするにしても、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を使用してください。

関連する問題