如何設計圓形頭像
- 很多時候,我們需要設計類似於頭像一樣的部分,但是這部分很多時候都是用圓形頭像,本篇博客就是討論如何設計圓形頭像
效果圖
實現代碼
- 利用widget下的cardview和imageview實現。
- 整體分爲兩個部分,先劃分總體佈局和圓形區域;接着在圓形區域插入目標圖片。
- 注意imageview部分,width和height一定是match_parent,因爲是在第一步劃分的圓形區域顯示的。
<android.support.v7.widget.CardView
android:id="@+id/cv_user_head"
android:layout_width="60dp"
android:layout_height="60dp"
app:cardCornerRadius="45dp"
app:cardElevation="10dp"
android:layout_marginTop="5dp"
android:layout_marginLeft="220dp"
app:cardPreventCornerOverlap="true"
>
<ImageView
android:id="@+id/tv_user_head"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/head"
android:scaleType="centerCrop"/>
</android.support.v7.widget.CardView>