查看本教程,了解如何创建 Android 形状并将该形状应用于您的布局:
http ://www.vogella.com/blog/2011/07/19/android-shapes/
具体来说,您使用 的<corners>
属性<shape>
来创建圆角,请参见上面引用的教程中的以下示例:
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"
/>
更新 2 - 这对我有用:
可绘制-hdpi/rounded.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#FFFFFFFF" />
<corners
android:bottomRightRadius="7dp"
android:bottomLeftRadius="7dp"
android:topLeftRadius="7dp"
android:topRightRadius="7dp"/>
<solid android:color="#00000000" />
</shape>
可绘制-hdpi/solid.xml:
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle">
<stroke android:width="2dp" android:color="#FFFFFFFF" />
<solid android:color="#00000000" />
</shape>
可绘制-hdpi/rounded_inside_corners.xml:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >
<item android:drawable="@drawable/rounded" />
<item android:drawable="@drawable/solid" />
</layer-list>
然后在我的活动布局中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@drawable/my_shape"
tools:context=".CameraActivity" >
<SurfaceView
android:id="@+id/surfaceView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/rounded_inside_corners"
android:layout_above="@+id/linearLayout1" />
<FrameLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button
android:id="@+id/buttonTakePicture"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:background="@drawable/camera_click_256"
android:gravity="center_horizontal" />
</FrameLayout>
</RelativeLayout>
结果是: