android圆角矩形的实现

在res/drawable目录下穿件shape的xml来实现圆角矩形效果。代码如下:

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

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

    <gradient
        android:angle="45"
        android:centerColor="#CCFFDD"
        android:endColor="#CCCCCC"
        android:startColor="#CCCCCC" />

    <padding
        android:bottom="7dp"
        android:left="7dp"
        android:right="7dp"
        android:top="7dp" />

</shape>

布局文件:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <Button
        android:id="@+id/button1"
        android:layout_width="140dp"
        android:layout_height="60dp"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@drawable/button"
        android:text="设置Shape的形状" />

    <LinearLayout
        android:layout_width="200dp"
        android:layout_height="100dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/button1"
        android:layout_marginTop="71dp"
       <span style="color:#ff0000;"> android:background="@drawable/button"</span>
        android:orientation="vertical" >

    </LinearLayout>

</RelativeLayout>
时间: 2024-08-05 23:46:58

android圆角矩形的实现的相关文章

android圆角矩形有背景颜色

android 圆角矩形,渐变颜色,自定义 首先,在drawable目录下写一个xml,名字随便起(只要符合规范),代码如下: <span style="color:#009900;"><span style="background-color: rgb(255, 255, 255);"><?xml version="1.0" encoding="utf-8"?> <shape xml

Android圆角矩形创建工具RoundRect类

用于把普通图片转换为圆角图像的工具类RoundRect类(复制即可使用): import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.graphics.Canvas; import android.graphics.Color; import android.graphics.Paint; import android.

android圆角矩形有边框无背景色

我们经常要用到圆角矩形,这也是现在的流行的样式..但是今天在工作中,遇到要写圆角矩形有边框但无背景色的button,本来想让妹子帮忙切图的,但是不想麻烦妹子,自己撑着,说可以做,结果弄了老半天菜搞定的,现在给大家看看,以后避免这麻烦...() <?xml version="1.0" encoding="utf-8"?> <shape xmlns:android="http://schemas.android.com/apk/res/and

android圆角矩形进度条

最近做项目,有个一个需求,就是圆角进度条.效果图如下. 当时项目时间很紧,没多去想怎么实现最佳,就直接把美工给的圆角进度条裁剪成了四份.来做 Canvas 剪切绘制.这样虽然也能达到效果,但是服用性很差.最近网上搜索了很长时间,发现Paint画笔,有遮挡层的功能.android.graphics.Paint.setXfermode(Xfermode xfermode) .其中一个参数就是 Mode.DST_OUT 显示底图与上层图非交集的底图图像.于是就有个思路,先绘制圆角矩形进度条,然后设置画

android圆角矩形背景

Android平台 使用方便 StateRoundRectDrawable mRoundRectDradable = new StateRoundRectDrawable(int normalCorlor, int pressColor); mRoundRectDradable.setBottomLeftRadius(0); mRoundRectDradable.setBottomRightRadius(0); ............. xxxxx.setBackgroundDrawable(

android圆角矩形出现四个角黑点的解决方法

只要在布局对应的activity的oncreate方法的第一行加上 getWindow().setBackgroundDrawableResource(android.R.color.transparent); 即可解决该问题

Android中实现圆角矩形及半透明效果。

注:本文由Colin撰写,版权所有!转载请注明原文地址,谢谢合作! 在做Android开发时,我们为了美观,有时候需要使用圆角矩形,或半透明之类的效果,在网页设计中很容易实现.但在Android开发中,要稍微麻烦一点,但实现起来也不算很难. 关于设定背景图片平铺的方法请参考上一篇文章:http://itcolin.com/archives/1153.html 一.首先,需要在drawable-mdpi目录里定义一个xml文件,我命名为frame 编写如下代码,其中corners 中定义每边的圆角

Android开发之自定义圆角矩形进度对话框

方式一:自定义对话框 public class ProgersssDialog extends Dialog { private ImageView img; private TextView txt; public ProgersssDialog(Context context) { super(context, R.style.progress_dialog); //加载布局文件 View view= View.inflate(context, R.layout.progress_dialo

Android自定义ViewGroup(一)——带箭头的圆角矩形菜单

今天要做一个带箭头的圆角矩形菜单,大概长下面这个样子: 要求顶上的箭头要对准菜单锚点,菜单项按压反色,菜单背景色和按压色可配置. 最简单的做法就是让UX给个三角形的图片往上一贴,但是转念一想这样是不是太low了点,而且不同分辨率也不太好适配,干脆自定义一个ViewGroup吧! 自定义ViewGroup其实很简单,基本都是按一定的套路来的. 一.定义一个attrs.xml 就是声明一下你的这个自定义View有哪些可配置的属性,将来使用的时候可以自由配置.这里声明了7个属性,分别是:箭头宽度.箭头