2017-04-10 24 views
0

所以基本上,我有这个全屏的DialogFragment,并且在进度条上有一个按钮(如果你点击按钮,它会消失,进度条可见)。我最初在一个活动中拥有xml,并且所有事情都按预期工作,但现在我想将其重构为全屏对话框片段。DialogFragment中的RelativeLayout - MarginBottom被忽略

问题是,这是ontop的进度栏的按钮现在对齐的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> 

什么特别奇怪的是,进度对齐按钮底部,但它仍然位于相同的位置之前

这里是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); 
    } 
} 

,我设置的onCreate

012的样式
<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

remove:'android:layout_alignParentBottom =“true”'from Button .. – rafsanahmad007

+0

这是不行的。我必须将其与父母底部对齐,然后将bottomMargin设置为70下倾 – TormundThunderfist

回答

0

试试这个布局。另外,相应地更改绘图,样式和字符串。

<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>