我需要iPhone風格的圓形佈局,背後有灰色背景。 (嘆息 - 總是複製iPhone)
我很沮喪,我無法找到掩蓋佈局的方法。這裏的大多數答案都表示使用背景圖片,但這不是我所需要的。
編輯:以前的答案使用FrameLayout
和設置android:foreground
繪製建議。這在視圖中引入了一些奇怪的填充。我更新了我的答案,使用更簡單的RelativeLayout
技術。
訣竅是使用RelativeLayout
;把你的佈局放在裏面。 在您的佈局下方,添加另一個ImageView
,將其background
設置爲合適的遮罩圖像幀。這將在您的其他佈局的頂部繪製。
在我的情況下,我做了一個9Patch文件,它是一個灰色的背景,用一個透明的圓角矩形切出來。

這爲您的基礎佈局完美的面具。
XML代碼如下 - 這是一個正常的佈局XML文件:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content" android:layout_width="fill_parent">
<!-- this can be any layout that you want to mask -->
<LinearLayout android:id="@+id/mainLayout"
android:layout_height="wrap_content"
android:layout_width="fill_parent" android:orientation="vertical"
android:background="@android:color/white">
<TextView android:layout_height="wrap_content"
android:layout_width="wrap_content" android:layout_gravity="center"
android:text="Random text..." />
</LinearLayout>
<!-- FRAME TO MASK UNDERLYING VIEW -->
<ImageView android:layout_height="fill_parent"
android:layout_width="fill_parent"
android:background="@drawable/grey_frame"
android:layout_alignTop="@+id/mainLayout"
android:layout_alignBottom="@+id/mainLayout" />
</RelativeLayout>
注意ImageView
在底部,對準頂部&底部到主佈局,與掩蔽圖像組:
android:background="@drawable/grey_frame"
此引用我9Patch文件 - 和口罩的基本佈局通過在前景中繪製。
下面是一個顯示標準佈局上的灰色圓角的示例。

HTH
我猜它會被巧妙地使用填充和邊距來解決 – schwiz 2010-12-01 19:23:15