これは、私がこのコードを使用するカードビュー(灰色のビュー)と画像ビュー(青いビュー)です。
<FrameLayout 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:background="@color/abc_search_url_text_normal"
Android:orientation="vertical">
<Android.support.v7.widget.CardView
Android:layout_width="match_parent"
Android:layout_height="100dp"
Android:layout_alignParentBottom="true"
Android:layout_gravity="bottom"
Android:layout_marginBottom="3dp"
Android:paddingTop="5dp"
app:cardBackgroundColor="@color/abc_input_method_navigation_guard">
</Android.support.v7.widget.CardView>
<ImageView
Android:layout_width="100dp"
Android:layout_height="100dp"
Android:layout_gravity="bottom"
Android:layout_marginBottom="30dp"
Android:layout_marginRight="10dp"
Android:scaleType="fitXY"
Android:src="@drawable/abc_ratingbar_full_material" />
</FrameLayout>
しかし結果として、私のイメージビューはcardviewの後ろに移動しますが、framelayoutではなくreletivelayoutを試しますが、同じ結果になります。
試してください:
RelativeLayoutを使用する
ImageViewを親の右/端に揃え、右/端のマージンを追加します
FABをカードビューの上部に配置し、負のマージンを追加します
<RelativeLayout
...>
<CardView
Android:id="@+id/cardView"
Android:layout_width="match_parent"
Android:layout_height="120dp"
/>
<ImageView
Android:id="@+id/fab"
Android:layout_width="wrap_content"
Android:layout_height="wrap_content"
Android:layout_alignParentRight="true"
Android:layout_alignTop="@id/cardView"
Android:layout_marginTop="-32dp"
Android:layout_marginRight="20dp"
/>
</RelativeLayout>
CardViewのデフォルトの標高はAPI 21+です。標高を操作して、ImageViewの標高より低くすることができます。
<Android.support.v7.widget.CardView xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
app:cardElevation="1dp"/>
<ImageView
Android:id="@+id/image_view_user"
Android:layout_width="48dp"
Android:layout_height="48dp"
Android:elevation="2dp"/>
pre 21で使用できます
overlayView.bringToFront();
root.requestLayout();
root.invalidate();
標高が異なる場合、これは21以上では機能しません
CardViewをFrameLayoutのように他のビューに配置するだけです。以下のように:
<FrameLayout xmlns:Android="http://schemas.Android.com/apk/res/Android"
Android:layout_width="match_parent"
Android:layout_height="wrap_content"
xmlns:app="http://schemas.Android.com/apk/res-auto"
Android:layout_marginStart="10sp"
Android:layout_marginEnd="10sp"
>
<FrameLayout
Android:layout_marginTop="15sp"
Android:layout_width="match_parent"
Android:layout_height="wrap_content">
<Android.support.v7.widget.CardView
Android:layout_width="match_parent"
Android:layout_height="100sp"
app:cardCornerRadius="5sp"
app:cardBackgroundColor="@color/colorPrimary">
<!--other view items -->
</Android.support.v7.widget.CardView>
</FrameLayout>
<de.hdodenhof.circleimageview.CircleImageView
Android:layout_width="90sp"
Android:layout_height="90sp"
app:civ_border_width="2dp"
Android:layout_marginStart="10sp"
app:civ_border_color="@color/colorPrimaryDark"
Android:id="@+id/profileImg"
Android:background="@drawable/ic_if_profle_1055000"
xmlns:app="http://schemas.Android.com/apk/res-auto"/>
スクリーンショット:
もう1つの方法は、イメージビューをカードビューでラップすることです。高さと幅の折り返しコンテンツで背景が透明であることを確認してください。背景は前のカードビューの上に表示されます。
CardViewをFrameLayoutでラップできますが、シャドウはトリミングされます。 Android:clipChildren = "false"を設定して修正します
<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:clipChildren="false"
Android:layout_height="140dp">
<FrameLayout
Android:id="@+id/frameLayout4"
Android:layout_width="match_parent"
Android:layout_height="match_parent"
Android:layout_margin="16dp"
Android:clipChildren="false">
<Android.support.v7.widget.CardView
app:cardCornerRadius="@dimen/card_radius"
Android:layout_width="match_parent"
Android:layout_height="match_parent">
</Android.support.v7.widget.CardView>
</FrameLayout>
</Android.support.constraint.ConstraintLayout>