2016-10-05 5 views
3

私はcardviewの上に整列する必要がある円形のimageviewを持っていますが、画像の半円がcardviewの外側にあり、画像の残りの半円がcardviewのようになります。 cardviewの上の境界の中心のように、それには円imageviewが存在します。カードビューの上部の画像ビュー

どうすればいいですか?私のプロキシは不便をおかけしてはいけないので、画像をアップロードできません。

enter image description here

答えて

3

<android.support.design.widget.FloatingActionButton 
    android:id="@+id/btn_contacts" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_margin="16dp" 
    android:scaleType="center" 
    android:src="@drawable/ic_contacts_36px" 
    app:fabSize="normal" 
    app:layout_anchor="@id/ll_cardView" 
    app:layout_anchorGravity="center|top" /> 

変更アプリ、このコードを試して、次のようにそれを実行してください:あなたのカードビューIDにlayout_anchor id名を。

+0

それは素敵な、 – eLemEnt

+0

@Elementありがとう働いた:D –

1

<FrameLayout> 

    <CardView> //set marginTop of 10 dp so that it will be half the height of CirccularImageView 

    <CircularImageView> //set some height to it like 20dp and gravity center horizontal. 
</FrameLayout> 
1

これはそうすることができます。

<?xml version="1.0" encoding="utf-8"?> 
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/activity_main" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    tools:context="com.simplebox.demo.MainActivity"> 

    <android.support.v7.widget.CardView 
     android:id="@+id/first" 
     app:cardBackgroundColor="@android:color/white" 
     app:cardCornerRadius="@dimen/cardview_default_radius" 
     app:cardElevation="4dp" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="50dp" 
     card_view:cardUseCompatPadding="true"> 

     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="300dp" 
      android:background="#FFF000"> 
     </RelativeLayout> 
    </android.support.v7.widget.CardView> 

    <ImageView 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_gravity="center_horizontal" 
     android:background="#000000" 
     android:contentDescription="@null" /> 

</FrameLayout> 

出力になります。 Round ImageにはCircular ImageViewを使用します。

enter image description here

関連する問題