2016-10-27 17 views
2

私のAlertDialogは、私が宣言することなく一番上に余白を付けて表示されます。AlertDialog:上に余白があります

import android.support.v7.app.AlertDialog;  

AlertDialog.Builder builder = new AlertDialog.Builder(this.act); 
builder.setView(R.layout.dialog_progress); 
builder.setCancelable(false); 
builder.setNegativeButton(R.string.cancel, null); 
builder.create().show(); 

dialog_progress.xml

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:gravity="center" 
      android:orientation="horizontal"> 

    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:indeterminate="true" 
     android:indeterminateTint="@color/colorPrimary"/> 

    <TextView 
     style="@style/TextView.Medium" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginLeft="20dp" 
     android:text="@string/fetching_location"/> 
</LinearLayout> 

enter image description here

私のアプリの他のダイアログがうまく見えます。

答えて

3

私のダイアログがとても奇妙にレイアウトされた理由をいくつかの時間のために検索した後、私はついに見つけた:

AndroidStudioは、パッケージandroid.support.v7.appからAlertDialogを輸入しました。私のアプリで使用している他のダイアログは、android.appパッケージからインポートされました。インポートのすべてを変更した後罰金に見えた:

enter image description here を(重力を変更し、いくつかのわずかなパディングを追加しました)

多分これは誰もが同じ問題を抱えてのに役立ちます。

+0

問題は、これらのダイアログが<= API19のようには見えないため、実際にダイアログボックスが必要なことです。あまりにも悪い彼らは奇妙に見えるパディングを追加します。おそらくこれはFABのようにpaddingCompatと関係がありますか?だから私は最初に互換性のために私のアプリに互換ダイアログを導入して以来、これは本当に問題を解決しません。 – lubosz

関連する問題