如何让button 圆角或者layout的四个角变圆角

CSS3圆角详解 - 阮一峰的网络日志
CSS3圆角详解
CSS3是样式表(style sheet)语言的最新版本,它的一大优点就是支持圆角。
网页设计大师的,清晰易懂地解释了CSS3圆角的各个方面,非常值得学习。以下就是我翻译的中文版。
=========================================
CSS3圆角详解
作者:Nicholas Zakas
译者:阮一峰
发表日期:日
一、CSS3圆角的优点
传统的圆角生成方案,必须使用多张图片作为背景图案。CSS3的出现,使得我们再也不必浪费时间去制作这些图片了,而且还有其他多个优点:
  * 减少维护的工作量。图片文件的生成、更新、编写网页代码,这些工作都不再需要了。
  * 提高网页性能。由于不必再发出多余的HTTP请求,网页的载入速度将变快。
  * 增加视觉可靠性。某些情况下(网络拥堵、服务器出错、网速过慢等等),背景图片会下载失败,导致视觉效果不佳。CSS3就不会发生这种情况。
二、border-radius属性
CSS3圆角只需设置一个属性:border-radius(含义是"边框半径")。你为这个属性提供一个值,就能同时设置四个圆角的半径。所有合法的CSS度量值都可以使用:em、ex、pt、px、百分比等等。
比如,下面是一个div方框:
现在设置它的圆角半径为15px:
  border-radius: 15
这条语句同时将每个圆角的"水平半径"(horizontal radius)和"垂直半径"(vertical radius)都设置为15px。
border-radius可以同时设置1到4个值。如果设置1个值,表示4个圆角都使用这个值。如果设置两个值,表示左上角和右下角使用第一个值,右上角和左下角使用第二个值。如果设置三个值,表示左上角使用第一个值,右上角和左下角使用第二个值,右下角使用第三个值。如果设置四个值,则依次对应左上角、右上角、右下角、左下角(顺时针顺序)。
  border-radius: 15px 5
  border-radius: 15px 5px 25
  border-radius: 15px 5px 25px 0
(左下角的半径为0,就变成直角了。)
border-radius还可以用斜杠设置第二组值。这时,第一组值表示水平半径,第二组值表示垂直半径。第二组值也可以同时设置1到4个值,应用规则与第一组值相同。
  border-radius: 15px 5px / 3
  border-radius: 15px 5px 25px / 3px 5
  border-radius: 15px 5px 25px 5px / 3px 5px 10px 15
三、单个圆角的设置
除了同时设置四个圆角以外,还可以单独对每个角进行设置。对应四个角,CSS3提供四个单独的属性:
  * border-top-left-radius
  * border-top-right-radius
  * border-bottom-right-radius
  * border-bottom-left-radius
这四个属性都可以同时设置1到2个值。如果设置1个值,表示水平半径与垂直半径相等。如果设置2个值,第一个值表示水平半径,第二个值表示垂直半径。
  border-top-left-radius: 15
  border-top-left-radius: 15px 5
四、浏览器支持
IE 9、Opera 10.5、Safari 5、Chrome 4和Firefox 4,都支持上述的border-radius属性。早期版本的Safari和Chrome,支持-webkit-border-radius属性,早期版本的Firefox支持-moz-border-radius属性。
目前来看,为了保证兼容性,只需同时设置-moz-border-radius和border-radius即可。
  -moz-border-radius: 15
  border-radius: 15
(注意:border-radius必须放在最后声明,否则可能会失效。)
另外,早期版本Firefox的单个圆角的语句,与标准语法略有不同。
  * -moz-border-radius-topleft(标准语法:border-top-left-radius)
  * -moz-border-radius-topright(标准语法:border-top-right-radius)
  * -moz-border-radius-bottomleft(标准语法:border-bottom-left-radius)
  * -moz-border-radius-bottomright(标准语法:border-bottom-right-radius)
五、注意事项
虽然各大浏览器都支持border-radius,但是在某些细节上,实现都不一样。当四个角的颜色、宽度、风格(实线框、虚线框等)、单位都相同时,所有浏览器的渲染结果基本一致;一旦四个角的设置不相同,就会出现很大的差异。比如,下面这段代码在不同的浏览器中,渲染结果就相差很大。
  border-color:
  border-style:
  border-width: 1px 2px 3
  border-top-color:
  border-radius: 5%;
另外,并非所有浏览器,都支持将圆角半径设为一个百分比值。
因此,目前最安全的做法,就是将每个圆角边框的风格和宽度,都设为一样的值,并且避免使用百分比值。
全球最大的 IT 咨询公司高德纳(Gartner),有一个"技术热门度曲线"模型(Gartner Hype Cycle)。
你可能听说过函数式编程(Functional programming),甚至已经使用了一段时间。
上周,《中文技术文档写作规范》加入了文件的命名规则。
很多人说,不知道怎么写文档,都是凭着感觉写。Android使用Shape实现布局圆角边框 -
- ITeye技术网站
博客分类:
Android使用 Shape 画边框线
&?xml version="1.0" encoding="utf-8"?&
&LinearLayout xmlns:Android="/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF"
android:orientation="vertical" &
&!-- 表格布局 --&
&TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip" &
&!-- 表格布局:第一行 --&
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_top_corner_no_bottom_line"
android:padding="10dip" &
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dip"
android:text="姓名:" &
&/TextView&
android:id="@+id/bankingYourNameEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@null"
android:singleLine="true" &
&/EditText&
&/TableRow&
&!-- 表格布局:第二行 --&
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_no_corner_without_bottom"
android:padding="10dip" &
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dip"
android:text="联系电话:" &
&/TextView&
android:id="@+id/bankingContactTelEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@null"
android:inputType="phone"
android:singleLine="true" &
&/EditText&
&/TableRow&
&!-- 表格布局:第三行 --&
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/shape_bottom_corner_no_top_line"
android:padding="10dip" &
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="10dip"
android:text="联系电话:" &
&/TextView&
android:id="@+id/bankingContactTelEditText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="@null"
android:inputType="phone"
android:singleLine="true" &
&/EditText&
&/TableRow&
&/TableLayout&
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="Button" /&
&/LinearLayout&
2、表格布局中每个TableRow表示一行,TableRow中的每个基本控件都是一列,这是一个三行两列的布局
这里的表格背景是自定义的shape,下面分别看一下三个shape的代码。
shape_top_corner_no_bottom_line.xml文件:顶部带圆角 白色背景 灰色边框 无下边框 长方体
&?xml version="1.0" encoding="UTF-8"?&
&!-- 顶部带圆角 白色背景 灰色边框 无下边框 长方体 --&
&layer-list xmlns:android="/apk/res/android"&
&solid android:color="#FFFFFF" /&
&corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /&
&stroke android:width="1dp" android:color="#ffa8abad" /&
&item android:top="1dp" android:left="1dp" android:right="1dp"&
&solid android:color="#FFFFFF" /&
&corners android:topLeftRadius="10dp" android:topRightRadius="10dp"
android:bottomRightRadius="0.1dp" android:bottomLeftRadius="0.1dp" /&
&stroke android:width="1dp" android:color="#ffffffff" /&
&/layer-list&
3、shape_no_corner_without_bottom.xml文件:不带圆角 白色背景 灰色边框 无下边框 长方体
&?xml version="1.0" encoding="UTF-8"?&
&!-- 不带圆角 白色背景 灰色边框 无下边框 长方体 --&
&layer-list xmlns:android="/apk/res/android" &
&solid android:color="#FFFFFF" /&
android:width="1dp"
android:color="#ffa8abad" /&
android:left="1dp"
android:right="1dp"
android:top="1dp"&
&solid android:color="#FFFFFF" /&
android:width="1dp"
android:color="#ffffffff" /&
&/layer-list&
4、shape_bottom_corner_no_top_line.xml文件:底部圆角 白色背景 灰色边框 长方体
&?xml version="1.0" encoding="UTF-8"?&
&!-- 底部圆角 白色背景 灰色边框 长方体 --&
&layer-list xmlns:android="/apk/res/android"&
&solid android:color="#FFFFFF" /&
&corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /&
&stroke android:width="1dp" android:color="#ffa8abad" /&
&item android:top="1dp" android:bottom="1dp" android:left="1dp" android:right="1dp"&
&solid android:color="#FFFFFF" /&
&corners android:topLeftRadius="0.1dp" android:topRightRadius="0.1dp"
android:bottomRightRadius="10dp" android:bottomLeftRadius="10dp" /&
&stroke android:width="1dp" android:color="#ffffffff" /&
&/layer-list&
shape_top_corner_no_bottom_line.xml
shape_no_corner_without_bottom.xml
shape_bottom_corner_no_top_line.xml
以上三个文件都存放在 drawable 中。
6、效果图查看附件。
文章引自:/Linux/61.htm
浏览 20066
浏览: 139097 次
来自: 北京
文章写得可以啊,就是自定义了一个scrollview,放到布局 ...
return前需要调用super.onInterceptTou ...
zhq502502 写道垃圾。写个博客毫无思路,看到就想骂,要 ...
不知道谁抄谁的,在几个网站上都看到了
垃圾。写个博客毫无思路,看到就想骂,要么你就别对外开放。艹

我要回帖

更多关于 button 圆角边框 的文章

 

随机推荐