gpt4 book ai didi

android - android中Imageview的圆角

转载 作者:塔克拉玛干 更新时间:2023-11-02 22:16:41 28 4
gpt4 key购买 nike

我在线性布局中有一个 TextView 和一个 ImageView 。 Textview 在顶部,imageview 在底部。我使用下面的线条为线性布局设置圆角。但是 imageview 角不是圆的。我只看到 linearlayout 的顶角是圆角的。 我怎样才能使 imageview 的底角变圆?(如果我删除 imageview,我会看到所有的角都是圆的)

rounded_corners.xml

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

<solid android:color="#ffffff" />


<corners
android:bottomLeftRadius="8dp"
android:bottomRightRadius="8dp"
android:topLeftRadius="8dp"
android:topRightRadius="8dp" />

</shape>

主.xml

  <LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="50dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="50dp"
android:background="@xml/rounded_corners"
android:orientation="vertical" >

<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="xxxxxxxx" />

<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scaleType="centerCrop"
android:src="@drawable/my_image_view" />
</LinearLayout>

屏幕截图: enter image description here

最佳答案

你可以把图片的左下角和右下角做成圆角,像这样:

enter image description here

代码:

public static Bitmap getRoundCornerBitmap(Bitmap bitmap, int radius) {
int w = bitmap.getWidth();
int h = bitmap.getHeight();
Bitmap output = Bitmap.createBitmap(w, h, Bitmap.Config.ARGB_8888);
Canvas canvas = new Canvas(output);

final Paint paint = new Paint(Paint.ANTI_ALIAS_FLAG);
final RectF rectF = new RectF(0, 0, w, h);

canvas.drawRoundRect(rectF, radius, radius, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, null, rectF, paint);

/**
* here to define your corners, this is for left bottom and right bottom corners
*/
final Rect clipRect = new Rect(0, 0, w, h - radius);
paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC));
canvas.drawRect(clipRect, paint);

paint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_IN));
canvas.drawBitmap(bitmap, null, rectF, paint);

bitmap.recycle();

return output;
}

此方法可以为您提供左下角和右下角圆角的图像。

关于android - android中Imageview的圆角,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12550311/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com