Add Frame or Border to ImageView and Drop-Shadow

会有一股神秘感。 提交于 2020-01-24 02:23:09

问题


What I'm trying to do will work better with an example image. As you can see below I have a grey background, ontop of that sits a container with some padding containing an image. The container also has a slight dropshadow to it.

What I want to know, is if there's so non-painstaking way of doing this in my layout.xml? In a normal HTML document this would've been easy. But since this is for a mobile app and for a number of screen resolutions and so on, it's proving a bit difficult.

Any advice?

Edit: I eventually settled using a 9patch image. Everyting went really smooth in the creation of it but when I actually use it in my app I see these dark stripes on the right and bottom of the image. The dropshadow seems to work, it's a very light dropshadow.. but those darn stripes??


回答1:


This can be done with proper padding and 9 patch image. See this link, may be it can help you.




回答2:


You can provide a border to a view by writing an xml file (say editBorder.xml) in drawable folder:

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" >

    <stroke 
        android:width="5dp"
        android:color="#EBDDE2" />

    <padding
        android:bottom="2dp"
        android:left="2dp"
        android:right="2dp"
        android:top="4dp" />

    <gradient
        android:centerColor="@color/white" 
        android:endColor="@color/white"
        android:startColor="@color/white" />

    <corners android:radius="8dp" />

</shape>

and to provide this border, use statement in ImageView as android:background="@drawable/editBorder"

This should solve your problem. :)




回答3:


ImageView having two property android:background and android:src

http://developer.android.com/reference/android/widget/ImageView.html

Create a blank white frame with drop shadow(Photoshop recommended).

So just do this

<ImageView android:id="@+id/imageView"
     android:layout_width="wrap_content"
     android:layout_height="wrap_content"
     android:src="@drawable/image"
     android:background="@drawable/whiteFrame" 
     android:padding="10dp" >
</ImageView>



回答4:


I found this imageView . It's may good for you



来源:https://stackoverflow.com/questions/10795550/add-frame-or-border-to-imageview-and-drop-shadow

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!