开发者

How do I create the equivalent of a css outset border in Android?

If you create an outset border in CSS the browser varies the border colour for each edge to make the shape appear to protrude from its parent.

Is there an easy way to do this in an android layout or do I need to set each line colour manually?

Update - added example below:

Example http://www.witz开发者_StackOverflow中文版elsucht.co.uk/googleplusheader.png


Set the background of an ImageView to a 9 patched drawable resource with the desired shadow/bevel around the edge. Lets say it takes 5 pixels to create the effect you want. Then set the padding of the ImageView to 5 pixels. Then set the bitmap to any image.

ImageView.setBackgroundDrawable

ImageView.setPadding

ImageView.setImageBitmap

Even easier, use a shape with a stroked border and set it as the background of the view:

<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#00000000" />
<stroke android:width="1px" android:color="#ffffff" /></shape>


I'm not aware of any native support for Views to have borders. Your question reminded me of this question that I was looking at recently:

Is there an easy way to add a border to the top and bottom of an Android View?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜