当前位置:首页 » 安卓系统 » androidshape圆角

androidshape圆角

发布时间: 2024-06-21 00:29:52

⑴ 如何给imageview设置圆角

android设置imageview圆角主要使用的是shape.xml文件,对四个角的角度进行设置,只要再imageview的background的属性上加上shape文件即可达到效果,示例如下:
shapeyuanjiao3.xml:
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<!-- 填充的颜色 -->
<solid android:color="#0000FF" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:topLeftRadius="@dimen/RoundedAmplitude" android:topRightRadius="@dimen/RoundedAmplitude"/>

<gradient
android:angle="270"
android:centerColor="#0000FF"
android:endColor="#0000FF"
android:startColor="#0000FF" />

</shape>
imageview、textview等的android:background="@drawable/shapeyuanjiao3"属性,设置尺寸、圆角(可以定制单独显示哪个角需要圆角)。可以参考我的csdn博客的这篇文章:http://blog.csdn.net/nihaoqiulinhe/article/details/46833819

⑵ Android如何设置圆角按钮

可以通过shape设置圆角
<!-- 设置圆角 -->
<corners android:radius="2dp" >
</corners>
扩展:
<?xml version="1.0" encoding="utf-8"?>
<!-- shape如果不声明形状默认是正方形 -->
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 设置填充色 -->

<solid android:color="#4285f4" >
</solid>
<!-- 设置边框的颜色和宽度 -->
<stroke
android:width="1dp"
android:color="#4285f4" >
</stroke>
</shape>
通过selector设置点击效果

button_bg.xml
<?xml version="1.0" encoding="utf-8"?>
<!-- 这个是用于控制按钮组背景的文件 -->
<selector xmlns:android="http://schemas.android.com/apk/res/android">

<!-- **点击时效果**********背景引用的资源*************************是否获得焦点*********************是否按下******* -->
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="false"/>
<item android:drawable="@drawable/button_p" android:state_focused="true" android:state_pressed="true"/>
<item android:drawable="@drawable/button_p" android:state_focused="false" android:state_pressed="true"/>

<!-- **************没有任何操作时显示的背景************** -->
<item android:drawable="@drawable/button_n"></item>
</selector>
在xml文件中设置button的background属性。
android:background="@drawable/button_bg"

⑶ android 圆角样式shape 的shape属性什么意思

shape官方给出了很多属性的解释,如下:
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle"
><!-- 其中rectagle表示矩形,oval表示椭圆,line表示水平直线,ring表示环形 -->
<!-- 节点属性介绍如下 -->
<corners />
<!-- 节点1:corners (圆角)
android:radius 圆角的半径 值越大角越圆
android:topLeftRadius 左上圆角半径
android:topRightRadius 右上圆角半径
android:bottomLeftRadius 左下圆角半径
android:bottomRightRadius 右下圆角半径
-->

<gradient />
<!-- 节点2: gradient (背景颜色渐变)
android:startColor 起始颜色
android:centerColor 中间颜色
android:endColor 末尾颜色
android:angle 渐变角度,必须为45的整数倍。
android:type 渐变模式 默认是linear(线性渐变)radial(环形渐变)
android:centerX X坐标
android:centerY Y坐标
android:gradientRadius radial(环形渐变)时需指定半径
-->

<padding />
<!-- 节点3: padding (定义内容离边界的距离)
android:left 左部边距
android:top 顶部边距
android:right 右部边距
android:bottom 底部边距
-->

<size />
<!-- 节点4:size (大小)
android:width 指定宽度
android:height 指定高度
-->

<solid />
<!-- 节点5:solid (填充)
android:color 指定填充的颜色
-->

<stroke />
<!-- 节点6:stroke (描边)
android:width 描边的宽度
android:color 描边的颜色
把描边弄成虚线的形式"- - -":
android:dashWidth 表示'-'这样一个横线的宽度
android:dashGap 表示之间隔开的距离
-->

</shape></span>

⑷ android代码的形式让button变成圆角 透明,如图

步骤如下:
------------------------------------------------------------------------
1. 先在res/drawable中定义一个shape.xml文件,具体的颜色你可以自己调
<?xml version="1.0" encoding="UTF-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

<!-- 填充的颜色:这里设置背景透明 -->
<solid android:color="@android:color/transparent" />
<!-- 边框的颜色 :不能和窗口背景色一样-->
<stroke
android:width="3dp"
android:color="#ffffff" />
<!-- 设置按钮的四个角为弧形 -->
<!-- android:radius 弧形的半径 -->
<corners android:radius="5dip" />

<!-- padding:Button里面的文字与Button边界的间隔 -->
<padding
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" />
</shape>
------------------------------------------------------------------------
2. 在你的Activity的xml(比如activity_main.xml)中定义按钮
<Button
android:id="@+id/roundButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/shape"
android:text=" 圆角按钮 " />

⑸ Android studio圆角矩形的布局如何设计

你可以使用shape定义一个圆角矩形,并将其作为布局的背景即可。
圆角矩形的shape代码如下:
//定义四个圆角 文件名shape_round_corner
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#ff00" />
<corners android:topLeftRadius="12dp"
android:topRightRadius="12dp"
android:bottomRightRadius="12dp"
android:bottomLeftRadius="12dp"/>
<stroke android:width="1dp" android:color="#ff0" />
</shape>
设置背景代码如下:
<LinearLayout
android:layout_width="300dp"
android:layout_height="300dp"
android:layout_marginBottom="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:alpha="0.8"
android:background="@drawable/shape_round_corner">
</LinearLayout>

⑹ android中我shape里写了边框颜色、圆角,但调用过去没实现。。。

你是说View占满了整个屏幕吗?这样的话就只能在layout中写一个布局文件,将View以一种组件的方式声明到.xml文件中,然后你可以在它的上下中声明其他的button或者textview或者ImageButton等。

⑺ Android studio中怎么将方形按钮设置成圆角以及渐变效果

一、在 studio中res 包下的drawable中建立一个shape的文件,系统会给你一个默认的方形然后你就可以开始设置你需要的效果。
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:Android="http://schemas.android.com/apk/res/android">

<!--填充背景色 -->
<solid android:color="#ffff00" /> //solid 指的是背景颜色的设置

<!--描边 他需要 2个参数,颜色 第二参数 宽度 -->
<stroke
android:width="2dp" //width 指的是边框的宽度
android:color="#ff00ff" /> //color指的是边框的颜色

<!-- 设置弧度 Radius设置所有角的弧度 --> //radius 指的就是角的弧度
<corners //方形存在四个角,我们可以同时设置四个角,也可以分开设置
android:bottomLeftRadius="20dp" //左下角
android:bottomRightRadius="20dp" //右下角
android:topLeftRadius="20dp" //左上角
android:topRightRadius="20dp" /> //右上角

//同时设置:<corners
android:Radius="20dp" /> //四个角同时设置

<!-- 渐变色 startColor 启示颜色 endColor最终颜色 type类型(如果类型为radial(径向渐变,一个圆心以半径的方式渐变),必须加上 android:gradientRadius="**")-->
<gradient
android:startColor="#ff0000" //开始颜色
android:endColor="#ffffff" //结束颜色
android:type="linear" /> //水平渐变 从左到右 type 指的是渐变的模式

<!--内容与边框的间距-->
<padding
android:bottom="15dp"
android:left="15dp"
android:right="15dp"
android:top="15dp" />

<!--如果设置了渐变色 那么背景颜色将不显示 -->

</shape>
<gradient>
shape的颜色渐变属性
attributes:

android:angle
Integer,代表渐变颜色的角度, 0 is left to right, 90 is bottom to top. 必须是45的整数倍.
默认是 0.该属性只有在type=linear情况下起作用,默认的type为linear。
默认情况下,从左到右:

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
/>

angle=270,从上到下 :

xml代码:<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:angle="270"
/>
android:startColor
Color. 颜色渐变的开始颜色,如angle=270中的 android:startColor="#000000"
android:endColor
Color. 颜色渐变的结束颜色,如angle=270中的 android:endColor="#ffffff"
android:centerColor
Color. 颜色渐变的中间颜色,主要用于多彩。

<gradient
android:startColor="#000000"
android:endColor="#ffffff"
android:centerColor="#ff0000"
/>
android:centerX
Float.(0 - 1.0) 相对X的渐变位置。
android:centerY
Float.(0 - 1.0) 相对Y的渐变位置。
这两个属性只有在type不为linear情况下起作用。
android:gradientRadius
Float. 渐变颜色的半径,单位应该是像素点. 需要 android:type="radial".
如果android:type="radial",没有设置android:gradientRadius,将会报错,error inflating class.

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
加入Android:centerColor属性

<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerColor="#000000"
android:centerX="0.5"
android:centerY="0.5"
android:gradientRadius="30"
android:type="radial"
/>
android:type
Value Description
"linear" 线性渐变.可以理解为 y=kx+b.
"radial" A radial gradient.圆形渐变,起始颜色从cenralX,centralY点开始。
"sweep" A sweeping line gradient.

centerX="0.2" centerX="0.2"

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.2"
android:centerX="0.2"
android:gradientRadius="30"
android:type="radial"
/>
type="sweep":

xml代码:
<gradient
android:startColor="#ff0000"
android:endColor="#ffffff"
android:centerX="0.5"
android:centerY="0.5"
android:type="sweep"
/>

⑻ 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);

```

⑼ android的圆角矩形按钮button如何实现按下按钮颜色会变

需要定义两个不同颜色的圆角xml布局,selector的drawable引用的就是圆角的xml,最后,布局调用的是selector。

⑽ 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" /> //虚线的间隔

热点内容
mp4反编译软件 发布:2024-10-25 16:47:33 浏览:998
哪个是提升电脑帧数的配置 发布:2024-10-25 16:43:45 浏览:95
以一种访问权限不允许的方式 发布:2024-10-25 16:38:32 浏览:404
嵌入式linux开发环境搭建 发布:2024-10-25 16:26:51 浏览:325
奥迪a4l乞丐版什么配置 发布:2024-10-25 16:20:33 浏览:411
python读取txt文件数据 发布:2024-10-25 16:07:36 浏览:23
获取局域网服务器的真实ip 发布:2024-10-25 16:01:36 浏览:28
多线程程序java 发布:2024-10-25 15:58:32 浏览:228
安卓最大的图片是哪个 发布:2024-10-25 15:55:06 浏览:467
云服务器登录小号 发布:2024-10-25 15:41:34 浏览:402