需要圆角距形的背景,可是直接用一终圆角的图片,但是因为Android屏幕分辨率太乱,为了能适应所有的分辨率,我们不可能事确定好宽度,虽然可以用draw9patch,但我一直没掌握那工具的用法,做出来的图片最终还是变形,但用下面的方法就永远不会变形,因为没有用图片,是用Android直接绘图. 最终的效果图: 新建一个drawable的xml文件,这里名为server_setting_bg:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >
<!-- 边缘线的宽度和颜色 -->
<stroke android:width="1px" android:color="#7d7a7a" />
<!-- 中间的背景色 -->
<solid android:color="#e4e4e4"/>
<!-- 设置四个角的角度 -->
<corners android:topLeftRadius="10dp" android:topRightRadius="10dp" android:bottomLeftRadius="10dp" android:bottomRightRadius="10dp"/>
</shape>
调用方法:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="300dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="20dp"
android:background="@drawable/server_setting_bg"
android:orientation="vertical" >
</LinearLayout>