2016-10-05 41 views
3

頂部我有圓形imageview,我需要對齊上述cardview,但它應該是這樣的圖像的半圈將是cardview之外,其餘一半的圖像圈在裏面cardview。像cardview的上邊框中心將出現圓形imageview的ImageView上cardview

我該如何做到這一點,我將無法上傳圖片,因爲我的代理不允許我爲抱歉給您造成不便。

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" /> 

更改應用:layout_anchor ID名稱從您的信用卡視圖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> 

輸出將是。圓形圖像使用圓形ImageView。

enter image description here