2012-12-13 27 views
1
<?xml version="1.0" encoding="UTF-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android"> 
<solid android:color="#FFFFFF" /> 
<stroke android:width="1dp" android:color="#000000" /> 
<padding android:left="1dp" android:top="1dp" android:right="1dp" 
android:bottom="1dp" /> 
</shape> 


我有這樣的代碼,使一個ImageView的邊境現在我想的是ImageView的得到的圖片了。
現在如何編輯此代碼以包含圖像呢?我的代碼,使一個imageview的圓角,現在我想用一個背景

+0

爲什麼不在imageview中設置圖像本身。 –

+0

查看下面發佈的解決方案。這將解決你的問題。 –

回答

1

試試這個:

<ImageView 
    android:id="@+id/my_imageView" 
    android:layout_width="fill_parent" 
    android:layout_height="300dp" 
    android:background="@drawable/rounded_imageview" 
    android:src="@drawable/ic_launcher"/> 

編輯:

ImageView myimage = (ImageView) findViewById(R.id.my_imageView); 
myimage.setImageResource(R.drawable.ic_launcher); 

你可以這樣做。

希望這可以幫助你。

謝謝。

+0

這很好,謝謝。 –

+0

不客氣。 :) –

0

您coud使用這種方法來獲得Rouded角落

BitmapShader shader; 
shader = new BitmapShader(bitmap, Shader.TileMode.CLAMP, Shader.TileMode.CLAMP); 

Paint paint = new Paint(); 
paint.setAntiAlias(true); 
paint.setShader(shader); 

RectF rect = new RectF(0.0f, 0.0f, width, height); 

// rect contains the bounds of the shape 
// radius is the radius in pixels of the rounded corners 
// paint contains the shader that will texture the shape 
canvas.drawRoundRect(rect, radius, radius, paint); 

輕鬆,你可以以這種方式添加更多的功能到ImageView的

相關問題