2017-04-10 4 views
0

Donc, fondamentalement, j'ai ce DialogFragment qui est en plein écran et a un bouton sur une barre de progression (si vous cliquez sur le bouton, il disparaît et la barre de progression est visible). J'ai d'abord eu le xml dans une activité et tout a fonctionné comme prévu là, mais maintenant je veux le refactoriser à un dialogue en plein écran.RelativeLayout dans DialogFragment - MarginBottom est ignoré

Le problème est, le bouton qui était juste au dessus de la barre de progression est maintenant aligné sur le fond du parentLayout

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_gps_loading" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/bg_setsensor" 
    tools:ignore="MissingPrefix" 
    > 

    <ImageView 
     android:layout_width="90dp" 
     android:layout_height="38dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="45dp" 
     /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:orientation="vertical" 
     > 

    <ImageView 
     android:layout_width="50dp" 
     android:layout_height="50dp" 
     android:layout_gravity="center_horizontal" 
     android:src="@drawable/ic_location" 
     /> 

    <TextView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_gravity="center_horizontal" 
     android:layout_marginTop="17dp" 
     android:gravity="center_horizontal" 
     android:text="@string/promptGpsPermissionBody" 
     style="@style/fullscreenText" 
     /> 
    </LinearLayout> 

    <ProgressBar 
     android:id="@+id/progressBar2" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/btnActivateGps" 
     android:layout_alignTop="@+id/btnActivateGps" 
     style="?android:attr/progressBarStyle" 
     /> 

    <Button 
     android:id="@+id/btnActivateGps" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_alignParentBottom="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="71dp" 
     android:layout_marginLeft="63dp" 
     android:layout_marginRight="63dp" 
     android:background="@color/white" 
     android:enabled="true" 
     android:visibility="visible" 
     /> 
</RelativeLayout> 

Ce qui est particulièrement étrange est que la barre de progression est aligné sur le bouton, mais il est toujours situé à la même position qu'avant

est ici le code java

public class GpsSensorDialog extends DialogFragment { 

    @NonNull @Override public Dialog onCreateDialog(Bundle savedInstanceState) { 
    AlertDialog.Builder builder = new AlertDialog.Builder(getActivity()); 
    LayoutInflater inflater = getActivity().getLayoutInflater(); 

    View view = inflater.inflate(R.layout.activity_gps_sensor, null); 

    builder.setView(view); 

    Dialog dialog = builder.create(); 

    if (dialog.getWindow() != null) { 
     dialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT)); 
     dialog.getWindow() 
      .setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
    } 
    return dialog; 
    } 

    @Override public void onCreate(@Nullable Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setStyle(STYLE_NO_TITLE, R.style.CustomDialog); 
    } 

    public static GpsSensorDialog newInstance() { 
    Bundle args = new Bundle(); 
    GpsSensorDialog fragment = new GpsSensorDialog(); 
    fragment.setArguments(args); 
    return fragment; 
    } 

    @Override public void onStart() { 
    super.onStart(); 
    getDialog().getWindow() 
     .setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT); 
    } 
} 

et le style que je mets en onCreate

<style name="CustomDialog"> 
    <item name="android:windowFrame">@null</item> 
    <item name="android:windowIsFloating">true</item> 
    <item name="android:windowContentOverlay">@null</item> 
    <item name="android:windowAnimationStyle">@android:style/Animation.Dialog</item> 
    <item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item> 
</style> 
+0

supprimer: 'android: layout_alignParentBottom = "true"' partir du bouton .. – rafsanahmad007

+0

qui ne va pas au travail. Je dois l'aligner au bas des parents, puis définir bottomMargin à 70 trempettes – TormundThunderfist

Répondre

0

Essayez cette mise en page. En outre, modifiez vos drawables, le style et les chaînes en conséquence.

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:id="@+id/activity_gps_loading" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@mipmap/ic_launcher" 
    tools:ignore="MissingPrefix"> 

    <ImageView 
     android:layout_width="90dp" 
     android:layout_height="38dp" 
     android:layout_alignParentTop="true" 
     android:layout_centerHorizontal="true" 
     android:layout_marginTop="45dp" /> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:layout_marginLeft="40dp" 
     android:layout_marginRight="40dp" 
     android:orientation="vertical"> 

     <ImageView 
      android:layout_width="50dp" 
      android:layout_height="50dp" 
      android:layout_gravity="center_horizontal" 
      android:src="@mipmap/ic_launcher" /> 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_gravity="center_horizontal" 
      android:layout_marginTop="17dp" 
      android:gravity="center_horizontal" 
      android:text="obsdas" /> 
    </LinearLayout> 

    <ProgressBar 
     android:id="@+id/progressBar2" 
     style="?android:attr/progressBarStyle" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_below="@+id/btnActivateGps" /> 

    <Button 
     android:id="@+id/btnActivateGps" 
     android:layout_width="match_parent" 
     android:layout_height="50dp" 
     android:layout_centerHorizontal="true" 
     android:layout_marginBottom="71dp" 
     android:layout_marginLeft="63dp" 
     android:layout_marginRight="63dp" 
     android:background="@android:color/white" 
     android:enabled="true" 
     android:visibility="visible" /> 
</RelativeLayout>