我需要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