2012-01-27 21 views

答えて

3
<RelativeLayout 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
> 
    <LinearLayout 
     android:orientation="horizontal" 
     android:width="wrap_content" 
     android:height="wrap_content" 
     android:layout_centerHorizontal="true"> 

... And two buttons here 
+0

ありがとう、私はこれを試してみます。 – Genry

+0

最後に私のために働いたのは、 'android:gracity =" center "'私は 'android:layout_centerHorizo​​ntal =" true "'の代わりに使用されています。それに応じて回答を編集する。また、アンドロイド:layout_widthとアンドロイド:layout_heightの代わりに、それぞれ、 'android:width'と' android:height'という小さなタイプミスがありました。この問題も解決しました – Genry

+0

あなたは正しいです。私は確かではなかったし、別のパラメータを忘れてしまった。私は自宅でEclipseを持っていないし、チェックできなかった。ごめんなさい。修正されました。 – Gangnus

1

AlertDialog.Builder builder = new AlertDialog.Builder(this); 
    builder.setMessage("Are you sure you want to exit?") 
      .setCancelable(false) 
      .setPositiveButton("Yes", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        MyActivity.this.finish(); 
       } 
      }) 
      .setNegativeButton("No", new DialogInterface.OnClickListener() { 
       public void onClick(DialogInterface dialog, int id) { 
        dialog.cancel(); 
       } 
      }); 
    AlertDialog alert = builder.create(); 

Android Devからは、これに似た何かを探していてもよいです。 「ポジティブ」と「ネガティブ」ボタンを設定して、あなたが望むものを言い、それぞれが独自のことをするようにすることができます。あなたの場合(そしてほとんどの場合)YesとNoはここで完璧です!

xmlファイルのいくつかの例は、私がこれまで使用していたものと同様に、そのリンクをたどって見つけることもできます。

Blog about custom dialogs. (Nice Example Code)

+0

ありがとうございましたが、私はレイアウトxmlファイルでそれを行う方法が欲しかったです。 – Genry

+0

@goryachex、心配する必要はありませんが、2番目のリンクにいくつかの例があります:)。 – sealz

0

あなたは、あなたがAlertDialogでビューとして設定するlayoutInflaterを使用し、とにかくあなたが望むダイアログのコンテンツのレイアウトを定義するためにXMLを使用することができます。

AlertDialog.Builder builder; 
AlertDialog alertDialog; 

Context mContext = getApplicationContext(); 
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE); 
View layout = inflater.inflate(R.layout.custom_dialog, (ViewGroup) findViewById(R.id.layout_root)); 

TextView text = (TextView) layout.findViewById(R.id.text); 
text.setText("Hello, this is a custom dialog!"); 
ImageView image = (ImageView) layout.findViewById(R.id.image); 
image.setImageResource(R.drawable.android); 

builder = new AlertDialog.Builder(mContext); 
builder.setView(layout); 
alertDialog = builder.create(); 

ドキュメントソース:http://developer.android.com/guide/topics/ui/dialogs.html#CustomDialog

+0

答えをありがとう。しかし、私はXMLレイアウト設定のみを参照していました。 – Genry

関連する問題