在自定义dialog中定义了布局,根布局用的ConstraintLayout 版本是1.0.2
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="39dp"
android:layout_marginRight="39dp"
android:background="@drawable/shape_solidffffff_corners8">
<ImageView
android:id="@+id/close"
android:layout_width="24dp"
android:layout_height="24dp"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="12dp"
android:src="@mipmap/close"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="标题"
android:textColor="#141414"
android:textSize="17sp"
android:textStyle="bold"
app:layout_constraintBottom_toTopOf="@+id/txt_content"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/txt_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/txt_title"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:layout_marginBottom="30dp"
android:gravity="center"
android:lineSpacingExtra="4dp"
android:text="内容"
android:textColor="#555555"
android:textSize="15sp"
app:layout_constraintBottom_toTopOf="@+id/txt_confirm"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txt_title" />
<TextView
android:id="@+id/txt_confirm"
android:layout_width="match_parent"
android:layout_height="38dp"
android:layout_below="@+id/txt_content"
android:layout_marginLeft="50dp"
android:layout_marginRight="50dp"
android:layout_marginBottom="22dp"
android:background="@drawable/shape_solidffb533_corners_round"
android:gravity="center"
android:text="@string/order_detail_confirm"
android:textColor="@color/white"
android:textSize="13sp"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>
预览效果:
不过在某些机型显示的效果不完整
升级ConstraintLayout 版本为1.1.2后显示正确