Java 屏幕方向更改后,DialogFragment内容消失

Java 屏幕方向更改后,DialogFragment内容消失,java,android,textview,android-constraintlayout,android-dialogfragment,Java,Android,Textview,Android Constraintlayout,Android Dialogfragment,我目前面临的问题是,当我将屏幕方向更改为横向模式时,对话框片段的全部内容消失 fragment\u dartboard.xml <?xml version="1.0" encoding="utf-8"?> <androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"

我目前面临的问题是,当我将屏幕方向更改为横向模式时,
对话框片段
的全部内容消失

fragment\u dartboard.xml

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/dartboard_fragment"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        android:src="@drawable/base"
        android:adjustViewBounds="true"
        android:scaleType="fitCenter"
        android:importantForAccessibility="no"
        android:id="@+id/base" />

</androidx.constraintlayout.widget.ConstraintLayout>
在纵向模式下

以横向模式


删除行
布局。添加视图(步骤)
,旋转后图片保持不变,但我的意图是在纵向底部显示
文本视图
,在横向显示右侧。

在方向更改时,我必须更改
图像视图的
布局参数

如此变化

if(getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            lp.startToEnd = R.id.base;
            lp.topToTop = R.id.dartboard_fragment;
            lp.bottomToBottom = R.id.dartboard_fragment;
        }


解决了问题。

在方向更改时,我必须更改
图像视图的
布局参数

如此变化

if(getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            lp.startToEnd = R.id.base;
            lp.topToTop = R.id.dartboard_fragment;
            lp.bottomToBottom = R.id.dartboard_fragment;
        }

解决了这个问题

if(getActivity().getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE) {
            view.findViewById(R.id.base).setLayoutParams(new ConstraintLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.MATCH_PARENT));
            lp.startToEnd = R.id.base;
            lp.topToTop = R.id.dartboard_fragment;
            lp.bottomToBottom = R.id.dartboard_fragment;
        }