Android imageView中的圆角
这是我的xml布局:Android imageView中的圆角,android,android-layout,android-imageview,Android,Android Layout,Android Imageview,这是我的xml布局: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="75dp" android:padding="3dp" > <ImageVi
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:padding="3dp" >
<ImageView
android:id="@+id/img"
android:layout_width="75dp"
android:layout_height="75dp"
android:scaleType="fitCenter"
/>
<TextView
android:id="@+id/name"
android:layout_width="208dp"
android:layout_height="75dp"
android:paddingLeft="15dp"
android:paddingTop="15dp" />
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center"
android:src="@drawable/ash_arrow" />
</LinearLayout>
如何用圆角显示我的
ImageView
?如果尝试为ImageView设置背景,用xml定义一个只包含“corner”属性的形状,会怎么样?诸如此类:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<corners android:radius="20dip" />
</shape>
ash\u arrow.xml
<?xml version="1.0" encoding="utf-8"?>
<shape
xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="oval">
<!--Background with solid color-->
<solid android:color="@color/colorWhite"/>
<!--background with gradient-->
<!--<gradient-->
<!--android:centerColor="#fff"-->
<!--android:centerX="50%"-->
<!--android:centerY="50%"-->
<!--android:endColor="#f0f"-->
<!--android:gradientRadius="100"-->
<!--android:startColor="#f00"-->
<!--android:type="radial"/>-->
<!--Stoke with dashed line-->
<!--<stroke-->
<!--android:width="8dp"-->
<!--android:color="#f00"-->
<!--android:dashGap="8dp"-->
<!--android:dashWidth="8dp"/>-->
<!--Stroke normal-->
<stroke
android:width="1dp"
android:color="@color/willow_grove"/>
<padding
android:bottom="0dp"
android:left="0dp"
android:right="0dp"
android:top="0dp"/>
</shape>
使用下面的代码。它可能会帮助你-
public static Bitmap getRoundedCornerBitmap(Bitmap bitmap) {
Bitmap output = Bitmap.createBitmap(bitmap.getWidth(),
bitmap.getHeight(), Config.ARGB_8888);
Canvas canvas = new Canvas(output);
final int color = 0xff424242;
final Paint paint = new Paint();
final Rect rect = new Rect(0, 0, bitmap.getWidth(), bitmap.getHeight());
final RectF rectF = new RectF(rect);
final float roundPx = 12;
paint.setAntiAlias(true);
canvas.drawARGB(0, 0, 0, 0);
paint.setColor(color);
canvas.drawRoundRect(rectF, roundPx, roundPx, paint);
paint.setXfermode(new PorterDuffXfermode(Mode.SRC_IN));
canvas.drawBitmap(bitmap, rect, rect, paint);
return output;
}
将位图图像传递到此方法中,并将其作为圆角。如果图像是png,则可以在drawable文件夹中创建自定义形状,设置其角点和颜色,并设置为ImageView背景。@Demonick,如果我使用jpg图像,它是否也适用?仅供参考,他问的是圆角ImageView不是圆角BitmapIt行得通。它将以编程方式将位图文件转换为
ImageView
性能可能会有问题。有没有什么方法可以实现硬加速?如何使用这个xml?如何显示圆角图像?它不是简单地替换图像吗?@ AmiGels:使用这一点-> Android:后台=“@ Dababy/AsHy箭矢”,并设置图像原始图像Android:SRC=“@ Dababel/IcLungisher”@ ArRun考虑编辑你的答案,因为它目前是错误的。