我得到了很多关于这个答案的赞成.所以我试着改善这个答案.可能这是与其他两个相比更好的方法,因为这个解决方案不需要修复布局或将屏幕分成相等的部分,所以可能这样做更好.
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="match_parent">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:id="@+id/viewA"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:orientation="horizontal">
android:id="@+id/subject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Thi"
android:textColor="@android:color/white"
android:textSize="17sp"
/>
android:id="@+id/viewB"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:orientation="horizontal">
android:id="@+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="20dp"
android:text="Thi"
android:textColor="@android:color/black"
android:textSize="17sp"
/>
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:clickable="true"
android:src="@drawable/plus"
app:layout_anchor="@+id/viewA"
app:layout_anchorGravity="bottom|right|end"/>
替代方式试试这个
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
// this is your first layout to put the big image
// use src or backgroud image as per requirement
android:background="@color/red_error"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
// this is your bottom layout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
// This is the imageview which overlay the first LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/success"
android:adjustViewBounds="true"
android:layout_gravity="center"/>
它看起来像这样
找到了另一个解决方案(编辑)
如果您的大图像尺寸是固定高度,您可以试试这个
android:layout_width="match_parent"
android:layout_height="match_parent" >
android:id="@+id/layoutTop"
android:background="@color/red_error"
android:layout_width="match_parent"
android:layout_height="200dp" >
android:id="@+id/layoutBottom"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_alignParentBottom="true"
android:layout_below="@id/layoutTop" >
android:id="@+id/overlapImage"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_above="@id/layoutBottom"
android:layout_centerHorizontal="true"
android:layout_marginBottom="-20dp"
android:adjustViewBounds="true"
android:src="@drawable/testimage" />
希望这会有所帮助.祝你好运