我正在使用
当显示对话框时,它会延伸到屏幕的边缘,并且布局检查器显示测量宽度超过16,000,000。更奇怪的是,
下面是对话框的类:
这里是布局文件
DialogFragment
构建自定义对话框。我注意到,使用各种ViewGroups作为对话框布局的根时会出现非常奇怪的行为。我认为这是由于系统窗口与显示对话框的方式之间的某种奇怪交互所致。在这个特定的实例中,我使用ConstraintLayout
作为布局的根视图。当显示对话框时,它会延伸到屏幕的边缘,并且布局检查器显示测量宽度超过16,000,000。更奇怪的是,
ConstraintLayout
定义了填充,但仍然可以在屏幕上看到。下面是对话框的类:
public class AgreementDialog extends DialogFragment {
// Bindings..
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.dialog_agreement, container);
ButterKnife.bind(this, view);
return view;
}
}
这里是布局文件
dialog_agreement
:<android.support.constraint.ConstraintLayout
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:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#fff"
android:padding="@dimen/margin_large"
android:layout_margin="@dimen/margin_xlarge"
>
<CheckBox
android:id="@+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
/>
<TextView
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_standard"
android:text="this is some text. "
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/checkbox"
/>
<TextView
android:id="@+id/id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="@dimen/margin_large"
android:text="123456789"
app:layout_constraintBottom_toTopOf="@+id/negative"
app:layout_constraintTop_toBottomOf="@id/description"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
/>
<Button
android:id="@+id/positive"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/confirm"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="24dp"/>
<Button
android:id="@+id/negative"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="20dp"
android:text="@string/cancel"
app:layout_constraintBaseline_toBaselineOf="@id/positive"
app:layout_constraintEnd_toStartOf="@id/positive"
/>
</android.support.constraint.ConstraintLayout>
问题:
- 为什么测量的宽度如此之大?
- 给定测量的宽度超过16,000,000,人们会期望结束填充也会超出屏幕。为什么它是可见的?
- 如何解决这些问题,以便可以显示正常包裹其内容的对话框?
编辑: 我注意到删除填充似乎会导致宽度达到那个很大的数字。保持填充使对话框保持正常的边缘距离屏幕,但剪辑内容。