I have a custom DialogFragment and it displays only half the height. Width is fine.I set height="match_parent" in my layout.My root Element is RelativeLayout. I do not know how to fix height problem.
Here is java class.
public class DefeatDialog extends DialogFragment {
public interface DialogListener {
void onDialogPositiveClick(DialogFragment dialog);
}
public DefeatDialog() {
}
DialogListener mListener;
DefeatAlertBinding binding;
@Override
public void onAttach(@NonNull Context context) {
super.onAttach(context);
try {
// Instantiate the NoticeDialogListener so we can send events to the host
mListener = (DialogListener) context;
} catch (ClassCastException e) {
// The activity doesn't implement the interface, throw exception
throw new ClassCastException(context.toString()
+ " must implement NoticeDialogListener");
}
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(), android.R.style.Theme_Black_NoTitleBar_Fullscreen);
LayoutInflater inflater = getActivity().getLayoutInflater();
View view = inflater.inflate(R.layout.defeat_alert, null, false);
builder.setView(view);
binding = DefeatAlertBinding.bind(view);
binding.startAgain.setOnClickListener((v -> {
mListener.onDialogPositiveClick(DefeatDialog.this);
}));
final AlertDialog dialog = builder.create();
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
dialog.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
dialog.show();
return dialog;
}
}
How can i fix that?Here my xml file.Here is my layout for DialogFragment. it does not display on full screen.Also not all part of xml displayed.
<layout 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">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/red"
android:orientation="vertical">
<ImageView
android:id="@+id/line"
android:layout_width="match_parent"
android:layout_height="35dp"
android:background="@drawable/line_defeat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.057"
tools:layout_editor_absoluteX="0dp" />
<ImageView
android:id="@+id/image"
android:layout_width="100dp"
android:layout_height="100dp"
android:background="@drawable/icon_defeat"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.498"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/line"
app:layout_constraintVertical_bias="0.036" />
<TextView
android:id="@+id/textView_1"
android:layout_width="400dp"
android:layout_height="80dp"
android:gravity="center"
android:text="@string/defeat"
android:textColor="@color/dark"
android:textSize="30sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/image"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView_2"
android:layout_width="400dp"
android:layout_height="80dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.454"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_1"
app:layout_constraintVertical_bias="0.131" />
<Button
android:id="@+id/start_again"
android:layout_width="200dp"
android:layout_height="40dp"
android:background="@drawable/button_win_defeat"
android:text="@string/button_defeat_win"
android:textColor="@color/colorWhite"
android:textSize="17sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.497"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView_2"
app:layout_constraintVertical_bias="0.024" />
</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
Here is my layout for DialogFragment. it does not display on full screen.Also not all part of xml displayed.