来自:http://www.dabu.info/android-shape-drawable-create-jian-liang-side-semicircle-backgound-button.html

Creating a rectangle shape with only two rounded edges

先上效果图: 第一种: 现在drawable/下创建 semi_round_backgroud.xml: semi_round_backgroud.xml:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 < ?xml version= "1.0" encoding= "utf-8" ? > <shape      xmlns :android="http ://schemas.android.com/apk/res/android"      android :shape="rectangle"      android :color="@color/colorAccent" >      <corners          android :radius="60dip"         / >      <stroke          android :width="0dp"          android :color="@color/colorAccent" / >      <solid          android :color="@color/colorAccent" / > </shape >
第二种: semi2.xml:
1 2 3 4 5 6 7 8 9 10 11 12 <? xml version = "1.0" encoding = "utf-8" ?> xmlns : android = "http://schemas.android.com/apk/res/android"        android : shape = "rectangle" >      android : color = "@color/colorAccent" />      android : height = "30dp" />              android : bottomRightRadius = "30dp"         android : bottomLeftRadius = "30dp"         android : topRightRadius = "30dp"         android : topLeftRadius = "30dp"         />
然后是activity_main.xml引用上面创建的背景图:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 <? xml version = "1.0" encoding = "utf-8" ?>     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"     tools : context = ".MainActivity" >              android : text = "Hello World!"         android : id = "@+id/tv1"         android : background = "@drawable/semi_round_backgroud"         android : layout_width = "wrap_content"         android : layout_height = "wrap_content"         android : layout_centerInParent = "true"         android : textSize = "25dp"         android : paddingTop = "8dp"         android : paddingBottom = "8dp"         android : paddingRight = "15dp"         android : paddingLeft = "15dp" />              android : text = "Hello World!"         android : id = "@+id/tv2"         android : background = "@drawable/semi2"         android : layout_width = "wrap_content"         android : layout_height = "wrap_content"         android : layout_centerInParent = "true"         android : textSize = "25dp"         android : paddingTop = "8dp"         android : paddingBottom = "8dp"         android : paddingRight = "15dp"         android : paddingLeft = "15dp"         android : layout_below = "@+id/tv1"         android : layout_marginTop = "15dp" />
这里,我发现一个问题,那就是android studio的布局预览功能是有问题的,也就是预览可以,但是并不一定就是在真实手机上呈现的效果,比如,第一种和第二种方法,在android studio的预览效果如下: 上面是第一种,下面是第二种。肉眼可以看出,第二种要比第一种半圆要尖一些。 但是在真实的手机所呈现的效果却没有这种区别,真实手机上的效果截图: 是不是两种一样的,所以,这个例子也告诉我们,android studio的预览功能不可靠,确切的说,应该是谷歌提供的界面预览工具不可靠,建议看真是效果,一定还是要在实体机上测试。

更多相关文章

  1. 在文字周围环绕一层阴影效果[android:shadow] 使用
  2. android 入门学习笔记 Button 常用的弹窗效果code
  3. 【Android自学笔记】为Android应用程序添加Rate功能
  4. Android仿WIN8系统磁贴点击下沉倾斜效果
  5. Android全屏对话框(附带延时关闭效果)
  6. Android 实现手机震动功能
  7. Android 简单的从本机获取相机功能 并且自动添加
  8. Android实现记住密码功能

随机推荐

  1. Mac 完全卸载 Android Studio
  2. android 按钮置灰效果
  3. android studio 配置Kotlin报错Error:Cau
  4. Android Studio常用插件
  5. TabHost
  6. Android Studio 使用技巧(6)
  7. android host修改
  8. android 从assets和res中读取文件
  9. Android实践之TabActivity
  10. android : 背景透明的 Dialog