2017-02-27 31 views
2

私はカスタムテーマでプログレスバーを表示しようとしています。しかし、センターの代わりに左上に来ている。カスタムテーマを使用しないと、中央に表示されますがフルスクリーンでは表示されません。これはテキストビューやその他の要素をバックグラウンドで悪く表示します。カスタムテーマと進捗ダイアログを初期化活動にAndroid:フルスクリーンのプログレスバーを中央に表示する方法

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent"> 

    <ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" /> 

</RelativeLayout> 

progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog); 
progressBar.setMessage("Please wait..."); 
progressBar.setCancelable(false); 

enter image description here

私はプログレスバーのプレビューを参照してください。次のコードとスクリーンショット

カスタムテーマですテーマだけでは以下のように正しく表示されます。しかし、それは間違った立場にあります。

enter image description here

+0

これは完了しているはずです。どこにデザインタブのプログレスバーが表示されますか? – mehulmpt

+0

@MehulMohan私はデザイン – codeit

+0

のスクリーンショットを追加しました。それは変です。 'android:gravity =" center "'をrelativelayoutに追加してみてください。 – mehulmpt

答えて

0

あなたがあなたの活動のレイアウトにプログレスバーを追加し、それは場所です設定し<include/>タグを使用することができますandroid:layout_centerHorizontal="true"android:layout_centerVertical="true"

1

を設定してみてください。カスタムスタイルはcustomProgressDialog.xmlの場合:あなたの活動の後

<include 
    layout="@layout/customProgressDialog" 
    android:id="@+id/customProgressDialog" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
/> 

ProgressDialog dialog = (ProgressDialog) findViewById(R.id.customProgressDialog); 
0

あなたは、テーマのIDが必要ですコンストラクタでレイアウトのIDを渡しています。

progressBar = new ProgressDialog(context, R.layout.layout_progress_dialog); 

コンストラクタは、あなたがstyle.xmlにカスタム属性を定義し、ここではそのスタイルのIDを渡す必要があり

public ProgressDialog(Context context, int theme) 

です。

関連する問題