开发者

Can I have a raised edge on a layout or component box?

I am writing an Android application and I have a box within a box on my UI. I changed the color of the backgrounds so the user can differentiate them. However, I want to know if I can have a raise edge or different color "edge" of a layout.

+_____________+
|   _______   |
|   |      |  |
|   |      |  |
|   |______|  |
+_____________+

Imagine that horrible box is the screen, and the outer box has a background of white and the inner box's开发者_运维百科 background is blue. Can I can make the 'edges' a different color and appear raised so the user can see a a better distinction between the boxes?


The best way to do this is to create your own background drawable for your View. I invite you to read about 9-patches and how to create them.


Probably the easiest way is to create a background image the way you like. 9 patch is the way to go, I think. Also you can consider other types of drawables: http://developer.android.com/guide/topics/resources/drawable-resource.html


You can try using one of the backgrounds built into Honeycomb for this. Not exactly what you're asking for but I think it does a good job separating the areas. Set the background of your view to:

android:background="?android:attr/detailsElementBackground"

And the end result is on the right pane:

http://2.bp.blogspot.com/-jTDarHrqACg/TV4qSsfBH8I/AAAAAAAAAEI/-N5mOnVv_-s/s1600/pic-2.png

But if you want it to work on pre-Honeycomb devices you'll have to take the background drawable, which is a small 9 patch, and use it as a resource in your project. It can be found in your SDK at platforms/android-13/data/res/drawable-mdpi and drawable-hdpi

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜