2016-05-28 8 views
0

半透明のダイアログを作成し、上から100dpのマージンを作成する必要があります。私のコードで
は、私はこの追加:マージンを持つ半透明のダイアログ

Dialog dialog = new Dialog(getActivity(), android.R.style.Theme_Translucent_NoTitleBar); 
    dialog.setContentView(R.layout.transparent_progress_bar); 

を、これはtransparent_progress_barです:

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:layout_marginTop="100dp" 
     > 

<ProgressBar 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_gravity="center" 
     android:background="@android:color/transparent" 
     android:indeterminate="true" 
     android:indeterminateDrawable="@drawable/rotate_progress_bar" 
     android:indeterminateOnly="true" 
     android:padding="@dimen/android_spacing_double"/> 

</RelativeLayout> 

が、それは動作しません。
テーマを変更したり、余白を追加するにはどうすればよいですか?

答えて

0

marginではなくandroid:layout_marginTop

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent" 
     android:paddingTop="100dp" 
     > 
     ... 

</RelativeLayout> 

の使用android:paddingTop親のレイアウトに

をあなたのレイアウトを整列させるUPDATE

<RelativeLayout 
     xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_height="match_parent" 
     android:layout_width="match_parent"> 

     <RelativeLayout 
      android:layout_height="match_parent" 
      android:layout_width="match_parent" 
      android:layout_marginTop="100dp"> 
      ... 

     </RelativeLayout> 

</RelativeLayout> 
+0

が動作しません... – edi233

+0

@ edi233私の更新の回答を確認してください –

0

はこれを試してみてください!! RES /値のtransparent_progress_bar.xml

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/relative_dialog_control" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="@android:color/transparent" 
android:layout_marginTop="8dp" 
> 

<View 
    android:id="@+id/view_close_top" 
    android:layout_width="match_parent" 
    android:layout_height="100dp" /> 

<RelativeLayout 
    android:id="@+id/relative_popup" 
    android:layout_width="match_parent" 
    android:layout_height="207dp" 
    android:layout_below="@+id/view_close_top" 
    android:layout_marginLeft="9dp" 
    android:layout_marginRight="9dp" 
    android:background="#FFFFFF" 
    android:padding="0dp"> 

    <ProgressBar 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:layout_gravity="center" 
    android:background="@android:color/transparent" 
    android:indeterminate="true" 
    android:indeterminateDrawable="@drawable/rotate_progress_bar" 
    android:indeterminateOnly="true" 
    android:padding="@dimen/android_spacing_double"/> 
</RelativeLayout> 

<View 
    android:id="@+id/view_close" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/relative_popup" /> 
</RelativeLayout> 

/

<style name="Theme.Transparent" parent="Theme.AppCompat.Light.Dialog"> 
    <item name="android:windowIsTranslucent">false</item> 
    <item name="android:windowBackground">@android:color/transparent</item> 
    <item name="windowNoTitle">true</item> 
</style> 

を追加style.xmlこれがコードするときショーダイアログ

private void showPopupControl() { 
    final AppCompatDialog dialog = new AppCompatDialog(MainActivity.this, R.style.Theme_Transparent); 
     //dialog.getWindow().clearFlags(WindowManager.LayoutParams.FLAG_DIM_BEHIND); 
    dialog.setContentView(R.layout.transparent_progress_bar); 
    ViewGroup.LayoutParams params = dialog.getWindow().getAttributes(); 
    params.width = ViewGroup.LayoutParams.MATCH_PARENT; 
    dialog.getWindow().setAttributes((android.view.WindowManager.LayoutParams) params); 

    dialog.findViewById(R.id.relative_dialog_control).setVisibility(View.VISIBLE); 
    dialog.findViewById(R.id.view_close).setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      dialog.dismiss(); 
     } 
    }); 
    dialog.findViewById(R.id.view_close_top).setOnClickListener(new View.OnClickListener() { 
     @Override 
     public void onClick(View view) { 
      dialog.dismiss(); 
     } 
    }); 

    dialog.show(); 
} 

happyCodingあります。

関連する問題