2017-03-01 76 views
1

我正在使用畢加索圖像並試圖將圖像放入圓形圖像視圖中,但圖片仍爲正方形。我該如何解決它?如何將圖像放在圓形圖像視圖中

Picasso.with(context).load(resId).resizeDimen(R.dimen.image_size, R.dimen.image_size).into(holder.mImageViewItem); 

IMAGE_SIZE = 60dp

繪製資源:

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
android:shape="oval"> 
<solid android:color="#FFF"/> 

和ImageView的:

<ImageView 
    android:id="@+id/picture_imageview_item" 
    android:layout_marginTop="15dp" 
    android:layout_marginLeft="25dp" 
    android:layout_marginBottom="15dp" 
    android:layout_width="60dp" 
    android:layout_height="60dp" 
    android:background="@drawable/buttonshape" /> 

回答

0

你可以用白色邊框和透明的一個簡單的圓形內容與形狀。

// res/drawable/circle.xml 

<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:innerRadius="0dp" 
    android:shape="ring" 
    android:thicknessRatio="1.9" 
    android:useLevel="false" > 
    <solid android:color="@android:color/transparent" /> 

    <stroke 
     android:width="10dp" 
     android:color="@android:color/white" /> 
</shape> 

然後創建一個可繪製的圖層列表,並將其作爲背景添加到您的圖像視圖中。

// res/drawable/img.xml 

    <?xml version="1.0" encoding="utf-8"?> 
    <layer-list xmlns:android="http://schemas.android.com/apk/res/android" > 

     <item android:drawable="@drawable/ic_launcher"/> 
     <item android:drawable="@drawable/circle"/> 

    </layer-list> 

並將其作爲背景添加到您的imageview。

<ImageView 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:background="@drawable/img"/> 

代替ic_launcher,您可以添加圖像。 謝謝!

+0

抱歉,但它的犯規幫助我。悲傷:( –

+0

有什麼問題? –

+0

沒有什麼變化:(會嘗試使用一些庫 –

0

您可以使用不同的庫來創建圓形圖像。這是我遇到的最好的一個是

Siyamed