我開發了一個rss應用程序。我希望包含標題和圖像的ListView具有帶圓角的圖像。我在線提供了示例代碼,但問題是圖像仍然是矩形。奇怪的部分是我有一個滑動菜單,當它切換時會將rs ListView推開,而它被推動的圖像有圓角!當他們停止推動動畫時,再次變成長方形。對我來說這是一個非常奇怪的問題,所以幫助? 四捨五入的圖像類:帶有圓角的ListView中的圖像
public class RoundedImageView extends ImageView
{
private float radius = 20.0f;
public RoundedImageView(Context context)
{
super(context);
}
public RoundedImageView(Context context,AttributeSet attrs)
{
super(context,attrs);
}
public RoundedImageView(Context context,AttributeSet attrs,int defStyle)
{
super(context,attrs,defStyle);
}
@SuppressLint("DrawAllocation")
@Override
protected void onDraw(Canvas canvas)
{
Path clipPath = new Path();
RectF rect = new RectF(0,0,getWidth(), getHeight());
clipPath.addRoundRect(rect, radius, radius, Path.Direction.CW);
canvas.clipPath(clipPath);
super.onDraw(canvas);
}
}
爲什麼ü這樣做?創建一個圓角的XML並設置爲您的imageview的背景。 –
https://github.com/vinc3m1/RoundedImageView – naidu