当前位置:首页 » 安卓系统 » 安卓如何有圆形外框

安卓如何有圆形外框

发布时间: 2023-05-12 04:06:12

1. android 圆角边框 阴影边框怎么设置

所谓添加阴影,就是两个画布从重叠,上方的画布小于下方的画布,阴影颜色为下方的画布的颜色。
item 中shape 的属性 (rectangle:矩形;line:线性;oval:椭圆;ring:环形),默认为矩形
corners //设置圆角幅度,必须是在shape=rectangle的时候,corners才有效
<corners
Android:radius="dimension" //全部的圆角半径
android:topLeftRadius="dimension" //左上角的圆角半径
android:topRightRadius="dimension" //右上角的圆角半径
android:bottomLeftRadius="dimension" //左下角的圆角半径
android:bottomRightRadius="dimension" /> //右下角的圆角半径
eg:<corners android:radius="10dp" />
solid用以指定内部填充色
e.g:<solid android:color="color" />
gradient //定义渐变色,可以定义两色渐变和三色渐变,及渐变样式
linear(线性渐变)、radial(放射性渐变)、sweep(扫描式渐变), 在构造放射性渐变时,要加上android:gradientRadius属性(渐变半径),即必须指定渐变半径的大小才会起作用。
<gradient
android:type=["linear" | "radial" | "sweep"] //共有3中渐变类型
android:angle="integer" //渐变角度,必须为45的倍数,0为从左到右,90为从上到下
android:centerX="float" //渐变中心X的相当位置,范围为0~1
android:centerY="float" //渐变中心Y的相当位置,范围为0~1
android:startColor="color" //渐变开始点的颜色
android:centerColor="color" //渐变中间点的颜色,在开始与结束点之间
android:endColor="color" //渐变结束点的颜色
android:gradientRadius="float" //渐变的半径,只有当渐变类型为radial时才有效
android:useLevel=["true" | "false"] /> //使用LevelListDrawable时就要设置为true。设为false时才有渐变效果
stroke //这是描边属性,可以定义描边的宽度,颜色,虚实线等
<stroke
android:width="dimension" //描边的宽度
android:color="color" //描边的颜色 // 以下两个属性设置虚线
android:dashWidth="dimension" //虚线的宽度,值为0时是实线
android:dashGap="dimension" /> //虚线的间隔

2. Android:如下关于绘制圆角矩形边框问题,怎么解决

paint.setAntiAlias(true);

尝试在画笔上设置抗锯齿

3. 我想在Android的一个网格视图中显示图片,并对这些图片添加一个圆角矩形边框,我该怎么做

移动工具 【V】 直接选取工具、组选取工具 【A】 钢笔、添加锚点、删除锚点、改变路径角度 【P】 添加锚点工具 【+】 删除锚点工具 【-】 文字、区域文字、路径文字、竖向文字、竖向区域文字、竖向路径文字 【T】 椭圆、多边形、星形、螺旋形 【L】 增加边数、倒角半径及螺旋圈数(在【L】、【M】状态下绘图) 【↑】 减少边数、倒角半径及螺旋圈数(在【L】、【M】状态下绘图) 【↓】 矩形、圆角矩形工具 【M】 画笔工具 【B】 铅笔、圆滑、抹除工具 【N】 旋转、转动工具 【R】 缩放、拉伸工具 【S】 镜向、倾斜工具 【O】 自由变形工具 【E】 混合、自动勾边工具 【W】 图表工具(七种图表) 【J】 渐变网点工具 【U】 渐变填色工具 【G】 颜色取样器 【I】 油漆桶工具 【K】 剪刀、餐刀工具 【C】 视图平移、页面、尺寸工具 【H】 放大镜工具 【Z】 默认前景色和背景色 【D】 切换填充和描边 【X】 标准屏幕模式、带有菜单栏的全屏模式、全屏模式 【F】 切换为颜色填充 【】 切换为无填充 【/】 临时使用抓手工具 【空格】 精确进行镜向、旋转等操作 选择相应的工具后按【回车】 复制物体 在【R】、【O】、【V】等状态下按【Alt】+【拖动】 文件操作 新建图形文件 【Ctrl】+【N】 打开已有的图像 【Ctrl】+【O】 关闭当前图像 【Ctrl】+【W】 保存当前图像 【Ctrl】+【S】 另存为... 【Ctrl】+【Shift】+【S】 存储副本 【Ctrl】+【Alt】+【S】 页面设置 【Ctrl】+【Shift】+【P】 文档设置 【Ctrl】+【Alt】+【P】 打印 【Ctrl】+【P】 打开“预置”对话框 【Ctrl】+【K】 回复到上次存盘之前的状态 【F12】 编辑操作 还原前面的操作(步数可在预置中) 【Ctrl】+【Z】 重复操作 【Ctrl】+【Shift】+【Z】 将选取的内容剪切放到剪贴板 【Ctrl】+【X】或【F2】 将选取的内容拷贝放到剪贴板 【Ctrl】+【C】 将剪贴板的内容粘到当前图形中 【Ctrl】+【V】或【F4】 将剪贴板的内容粘到最前面 【Ctrl】+【F】 将剪贴板的内容粘到最后面 【Ctrl】+【B】 删除所选对象 【DEL】 选取全部对象 【Ctrl】+【A】 取消选择 【Ctrl】+【Shift】+【A】 再次转换 【Ctrl】+【D】 发送到最前面 【Ctrl】+【Shift】+【]】 向前发送 【Ctrl】+【]】 发送到最后面 【Ctrl】+【Shift】+【[】 向后发送 【Ctrl】+【[】 群组所选物体 【Ctrl】+【G】 取消所选物体的群组 【Ctrl】+【Shift】+【G】 锁定所选的物体 【Ctrl】+【2】 锁定没有选择的物体 【Ctrl】+【Alt】+【Shift】+【2】 全部解除锁定 【Ctrl】+【Alt】+【2】 隐藏所选物体 【Ctrl】+【3】 隐藏没有选择的物体 【Ctrl】+【Alt】+【Shift】+【3】 显示所有已隐藏的物体 【Ctrl】+【Alt】+【3】 联接断开的路径 【Ctrl】+【J】 对齐路径点 【Ctrl】+【Alt】+【J】 调合两个物体 【Ctrl】+【Alt】+【B】 取消调合 【Ctrl】+【Alt】+【Shift】+【B】 调合选项 选【W】后按【回车】 新建一个图像遮罩 【Ctrl】+【7】 取消图像遮罩 【Ctrl】+【Alt】+【7】 联合路径 【Ctrl】+【8】 取消联合 【Ctrl】+【Alt】+【8】 图表类型 选【J】后按【回车】 再次应用最后一次使用的滤镜 【Ctrl】+【E】 应用最后使用的滤镜并调节参数 【Ctrl】+【Alt】+【E】 文字处理 文字左对齐或顶对齐 【Ctrl】+【Shift】+【L】 文字中对齐 【Ctrl】+【Shift】+【C】 文字右对齐或底对齐 【Ctrl】+【Shift】+【R】 文字分散对齐 【Ctrl】+【Shift】+【J】 插入一个软回车 【Shift】+【回车】 精确输入字距调整值 【Ctrl】+【Alt】+【K】 将字距设置为0 【Ctrl】+【Shift】+【Q】 将字体宽高比还原为1比1 【Ctrl】+【Shift】+【X】 左/右选择 1 个字符 【Shift】+【←】/【→】 下/上选择 1 行 【Shift】+【↑】/【↓】 选择所有字符 【Ctrl】+【A】 选择从插入点到鼠标点按点的字符 【Shift】加点按 左/右移动 1 个字符 【←】/【→】 下/上移动 1 行 【↑】/【↓】 左/右移动1个字 【Ctrl】+【←】/【→】 将所选文本的文字大小减小2 点象素 【Ctrl】+【Shift】+【】 将所选文本的文字大小减小10 点象素 【Ctrl】+【Alt】+【Shift】+【】 将行距减小2点象素 【Alt】+【↓】 将行距增大2点象素 【Alt】+【↑】 将基线位移减小2点象素 【Shift】+【Alt】+【↓】 将基线位移增加2点象素 【Shift】+【Alt】+【↑】 将字距微调或字距调整减小20/1000ems 【Alt】+【←】 将字距微调或字距调整增加20/1000ems 【Alt】+【→】 将字距微调或字距调整减小100/1000ems 【Ctrl】+【Alt】+【←】 将字距微调或字距调整增加100/1000ems 【Ctrl】+【Alt】+【→】 光标移到最前面 【HOME】 光标移到最后面 【END】 选择到最前面 【Shift】+【HOME】 选择到最后面 【Shift】+【END】 将文字转换成路径 【Ctrl】+【Shift】+【O】 视图操作 将图像显示为边框模式(切换) 【Ctrl】+【Y】 对所选对象生成预览(在边框模式中) 【Ctrl】+【Shift】+【Y】 放大视图 【Ctrl】+【+】 缩小视图 【Ctrl】+【-】 放大到页面大小 【Ctrl】+【0】 实际象素显示 【Ctrl】+【1】 显示/隐藏所路径的控制点 【Ctrl】+【H】 隐藏模板 【Ctrl】+【Shift】+【W】 显示/隐藏标尺 【Ctrl】+【R】 显示/隐藏参考线 【Ctrl】+【;】 锁定/解锁参考线 【Ctrl】+【Alt】+【;】 将所选对象变成参考线 【Ctrl】+【5】 将变成参考线的物体还原 【Ctrl】+【Alt】+【5】 贴紧参考线 【Ctrl】+【Shift】+【;】 显示/隐藏网格 【Ctrl】+【”】 贴紧网格 【Ctrl】+【Shift】+【”】 捕捉到点 【Ctrl】+【Alt】+【”】 应用敏捷参照 【Ctrl】+【U】 显示/隐藏“字体”面板 【Ctrl】+【T】 显示/隐藏“段落”面板 【Ctrl】+【M】 显示/隐藏“制表”面板 【Ctrl】+【Shift】+【T】 显示/隐藏“画笔”面板 【F5】 显示/隐藏“颜色”面板 【F6】/【Ctrl】+【I】 显示/隐藏“图层”面板 【F7】 显示/隐藏“信息”面板 【F8】 显示/隐藏“渐变”面板 【F9】 显示/隐藏“描边”面板 【F10】 显示/隐藏“属性”面板 【F11】 显示/隐藏所有命令面板 【TAB】 显示或隐藏工具箱以外的所有调板 【Shift】+【TAB】 选择最后一次使用过的面板 【Ctrl】+【~】

4. android 如何把正方形图片显示圆形

Android应用开发中,很多头像都要求显示成圆形的,这就可以使用android的canvas、paint这些类来进行设置圆形,先设置paint的样式为圆形,然后把你要设置成圆形的图片重新赋值给paint这个类:canvas.drawBitmap(tempBmp, rect, rect, paint);

核心代码如下(引用这位前辈:http://blog.sina.com.cn/s/blog_7607703f0101dhlj.html,我增加一些注释,原来是没有注释):

java">packagecom.liang.round;
importandroid.annotation.SuppressLint;
importandroid.content.Context;
importandroid.graphics.Bitmap;
importandroid.graphics.Bitmap.Config;
importandroid.graphics.BitmapFactory;
importandroid.graphics.Canvas;
importandroid.graphics.Paint;
importandroid.graphics.PorterDuff;
importandroid.graphics.PorterDuffXfermode;
importandroid.graphics.Rect;
importandroid.view.View;
publicclassMyViewextendsView{
privateBitmapbmp=null;
privatePaintpaint=null;
publicMyView(Contextcontext){
super(context);
//TODOAuto-generatedconstructorstub
paint=newPaint();//实例化画笔类
BitmapFactory.Optionsoptions=newBitmapFactory.Options();
options.inJustDecodeBounds=true;
BitmapFactory.decodeResource(context.getResources(),R.drawable.test,options);//获得你存放在drawable下的正方形图片
options.inJustDecodeBounds=false;
BitmaptempBmp=BitmapFactory.decodeResource(context.getResources(),R.drawable.test,options);//实例化一个bitmap图片类
intwidth=options.outWidth;
intheight=options.outHeight;
intsize=width>height?height:width;//边框
intpos=(int)(size/2);
doubleradius=pos*Math.sin(45*180/Math.PI);//半径
size=(int)(radius*2);
pos=(int)(size/2);
bmp=Bitmap.createBitmap(size,size,Config.ARGB_8888);
Canvascanvas=newCanvas(bmp);
Rectrect=newRect(0,0,size,size);
paint.setAntiAlias(true);
canvas.drawCircle(pos,pos,(float)radius,paint);
paint.setXfermode(newPorterDuffXfermode(PorterDuff.Mode.SRC_ATOP));
canvas.drawBitmap(tempBmp,rect,rect,paint);
tempBmp.recycle();
}
@SuppressLint("DrawAllocation")
@Override
protectedvoidonDraw(Canvascanvas){
//TODOAuto-generatedmethodstub
super.onDraw(canvas);
if(bmp!=null){
if(!bmp.isRecycled()){
canvas.drawBitmap(bmp,100,100,paint);
}
}
}
}

5. android设置控件样式(边框颜色,圆角)和图片样式(圆角)

本文链接:https://blog.csdn.net/weixin_37577039/article/details/79090433

```

<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

    <solid android:color="@color/colorAccent" />

    <!-- 这里是设置为四周 也可以单独设置某个位置为圆角-->

    <corners android:topLeftRadius="5dp"

        android:topRightRadius="5dp"

        android:bottomRightRadius="5dp"

        android:bottomLeftRadius="5dp"/>

    <stroke android:width="1dp" android:color="#000000" />

</shape

```

```
<?xml version="1.0" encoding="UTF-8"?>

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">   

<!-- 边框颜色值 -->

<item>   

      <shape>   

            <solid android:color="#3bbaff" />   

      </shape>   

</item>   

<!--这个是按钮边框设置为四周 并且宽度为1-->

<item

android:right="1dp"

android:left="1dp"

android:top="1dp"

android:bottom="1dp">

    <shape>   

<!--这个是背景颜色-->

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

<!--这个是按钮中的字体与按钮内的四周边距-->

          <padding android:bottom="10dp"   

                android:left="10dp"   

                android:right="10dp"   

                android:top="10dp" />   

    </shape>       

</item>   

</layer-list>

```

使用:

```android:background="@drawable/button_edge"```

```
<?xml version="1.0" encoding="UTF-8"?>

<shape

    xmlns:android="http://schemas.android.com/apk/res/android"

    android:shape="rectangle">

    <!-- 填充的颜色 -->

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

    <!-- android:radius 弧形的半径 -->

    <!-- 设置按钮的四个角为弧形 -->

    <corners

    android:radius="5dip" /> 

    <!--也可单独设置-->

    <!-- <corners -->

  <!-- android:topLeftRadius="10dp"-->

  <!-- android:topRightRadius="10dp"-->

  <!-- android:bottomRightRadius="10dp"-->

  <!--  android:bottomLeftRadius="10dp"-->

<!--  />  -->

        **设置文字padding**

    <!-- padding:Button里面的文字与Button边界的间隔 -->

    <padding

        android:left="10dp"

        android:top="10dp"

        android:right="10dp"

        android:bottom="10dp"

        />

</shape>

```

```
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http://schemas.android.com/apk/res/android">

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

    <corners android:topLeftRadius="10dp"

        android:topRightRadius="10dp"

        android:bottomRightRadius="10dp"

        android:bottomLeftRadius="10dp"/>

</shape>

```

使用:

```

android:background="@drawable/image_circle"

```

```
Glide.with(MainActivity.this).load(croppedUri)

.transform(new GlideRectRound(MainActivity.this,6)).into(headIcon);

```

```

import android.content.Context;

import android.content.res.Resources;

import android.graphics.Bitmap;

import android.graphics.BitmapShader;

import android.graphics.Canvas;

import android.graphics.Paint;

import android.graphics.RectF;

import android.util.Log;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;

import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

/**

* Created by SiHao on 2018/3/3.

* Glide 的 圆角 图片 工具类

*/

public class GlideRectRound extends BitmapTransformation {

    private static float radius = 0f;

    // 构造方法1 无传入圆角度数 设置默认值为5

    public GlideRectRound(Context context) {

        this(context, 5);

    }

    // 构造方法2 传入圆角度数

    public GlideRectRound(Context context, int dp) {

        super(context);

        // 设置圆角度数

        radius = Resources.getSystem().getDisplayMetrics().density * dp;

    }

    // 重写该方法 返回修改后的Bitmap

    @Override

    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {

        return rectRoundCrop(pool,toTransform);

    }

    @Override

    public String getId() {

        Log.e("getID",getClass().getName() + Math.round(radius));

        return getClass().getName() + Math.round(radius);  // 四舍五入

    }

    private Bitmap rectRoundCrop(BitmapPool pool, Bitmap source){

        if (source == null) return null;

        Bitmap result = pool.get(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888); // ARGB_4444——代表4x4位ARGB位图,ARGB_8888——代表4x8位ARGB位图

        if (result == null) {

            result = Bitmap.createBitmap(source.getWidth(), source.getHeight(), Bitmap.Config.ARGB_8888);

        }

        Canvas canvas = new Canvas(result);

        Paint paint = new Paint();

        // setShader 对图像进行渲染

        // 子类之一 BitmapShader设置Bitmap的变换  TileMode 有CLAMP (取bitmap边缘的最后一个像素进行扩展),REPEAT(水平地重复整张bitmap)

        //MIRROR(和REPEAT类似,但是每次重复的时候,将bitmap进行翻转)

        paint.setShader(new BitmapShader(source, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));

        paint.setAntiAlias(true);  // 抗锯齿

        RectF rectF = new RectF(0f, 0f, source.getWidth(), source.getHeight());

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

        return result;

    }

}

```

圆角:

```

import android.content.Context;

import android.graphics.Bitmap;

import android.graphics.BitmapShader;

import android.graphics.Canvas;

import android.graphics.Paint;

import com.bumptech.glide.load.engine.bitmap_recycle.BitmapPool;

import com.bumptech.glide.load.resource.bitmap.BitmapTransformation;

/**

* Created by SiHao on 2018/3/3.

* Glide圆形图片工具类

*/

public class GlideCircleBitmap extends BitmapTransformation{

    public GlideCircleBitmap(Context context) {

        super(context);

    }

    // 重写该方法 返回修改后的Bitmap

    @Override

    protected Bitmap transform(BitmapPool pool, Bitmap toTransform, int outWidth, int outHeight) {

        return circleCrop(pool, toTransform);

    }

    @Override

    public String getId() {

        return getClass().getName();

    }

    private static Bitmap circleCrop(BitmapPool pool, Bitmap source) {

        if (source == null) return null;

        // 边长取长宽最小值

        int size = Math.min(source.getWidth(), source.getHeight());

        int x = (source.getWidth() - size) / 2;

        int y = (source.getHeight() - size) / 2;

        // TODO this could be acquired from the pool too

        Bitmap squared = Bitmap.createBitmap(source, x, y, size, size);

        Bitmap result = pool.get(size, size, Bitmap.Config.ARGB_8888);// ARGB_4444——代表4x4位ARGB位图,ARGB_8888——代表4x8位ARGB位图

        if (result == null) {

            result = Bitmap.createBitmap(size, size, Bitmap.Config.ARGB_8888);

        }

        Canvas canvas = new Canvas(result);

        Paint paint = new Paint();

        // setShader 对图像进行渲染

        // 子类之一 BitmapShader设置Bitmap的变换  TileMode 有CLAMP (取bitmap边缘的最后一个像素进行扩展),REPEAT(水平地重复整张bitmap)

        //MIRROR(和REPEAT类似,但是每次重复的时候,将bitmap进行翻转)

        paint.setShader(new BitmapShader(squared, BitmapShader.TileMode.CLAMP, BitmapShader.TileMode.CLAMP));

        paint.setAntiAlias(true);// 抗锯齿

        // 半径取 size的一半

        float r = size / 2f;

        canvas.drawCircle(r, r, r, paint);

        return result;

    }

}

```

```

URL url = new URL(String类型的字符串); //将String类型的字符串转换为URL格式

holder.UserImage.setImageBitmap(BitmapFactory.decodeStream(url.openStream()));

```

```

//得到资源文件的BitMap

Bitmap image= BitmapFactory.decodeResource(getResources(),R.drawable.dog);

//创建RoundedBitmapDrawable对象

RoundedBitmapDrawable roundImg =RoundedBitmapDrawableFactory.create(getResources(),image);

//抗锯齿

roundImg.setAntiAlias(true);

//设置圆角半径

roundImg.setCornerRadius(30);

//设置显示图片

imageView.setImageDrawable(roundImg);

```

```
//如果是圆的时候,我们应该把bitmap图片进行剪切成正方形, 然后再设置圆角半径为正方形边长的一半即可

  Bitmap image = BitmapFactory.decodeResource(getResources(), R.drawable.dog);

  Bitmap bitmap = null;

  //将长方形图片裁剪成正方形图片

  if (image.getWidth() == image.getHeight()) {

      bitmap = Bitmap.createBitmap(image, image.getWidth() / 2 - image.getHeight() / 2, 0, image.getHeight(), image.getHeight());

  } else {

      bitmap = Bitmap.createBitmap(image, 0, image.getHeight() / 2 - image.getWidth() / 2, image.getWidth(), image.getWidth());

  }

  RoundedBitmapDrawable roundedBitmapDrawable = RoundedBitmapDrawableFactory.create(getResources(), bitmap);

  //圆角半径为正方形边长的一半

  roundedBitmapDrawable.setCornerRadius(bitmap.getWidth() / 2);

  //抗锯齿

  roundedBitmapDrawable.setAntiAlias(true);

  imageView.setImageDrawable(roundedBitmapDrawable);

```

热点内容
内置存储卡可以拆吗 发布:2025-05-18 04:16:35 浏览:336
编译原理课时设置 发布:2025-05-18 04:13:28 浏览:378
linux中进入ip地址服务器 发布:2025-05-18 04:11:21 浏览:612
java用什么软件写 发布:2025-05-18 03:56:19 浏览:32
linux配置vim编译c 发布:2025-05-18 03:55:07 浏览:107
砸百鬼脚本 发布:2025-05-18 03:53:34 浏览:945
安卓手机如何拍视频和苹果一样 发布:2025-05-18 03:40:47 浏览:742
为什么安卓手机连不上苹果7热点 发布:2025-05-18 03:40:13 浏览:803
网卡访问 发布:2025-05-18 03:35:04 浏览:511
接收和发送服务器地址 发布:2025-05-18 03:33:48 浏览:372