简体   繁体   English

将帧或边框添加到ImageView和Drop-Shadow

[英]Add Frame or Border to ImageView and Drop-Shadow

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? 我想知道的是,如果在layout.xml中这样做非常费力吗? In a normal HTML document this would've been easy. 在普通的HTML文档中,这很简单。 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. 编辑:我最终决定使用9patch图像。 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. Everyting在创建过程中非常流畅但是当我在我的应用程序中实际使用它时,我会在图像的右侧和底部看到这些暗条纹。 The dropshadow seems to work, it's a very light dropshadow.. but those darn stripes?? 这些阴影似乎有效,它是一个非常浅的阴影..但那些条纹?

在此输入图像描述

You can provide a border to a view by writing an xml file (say editBorder.xml) in drawable folder: 您可以通过在drawable文件夹中写入xml文件(例如editBorder.xml)来为视图提供边框:

<?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" 并提供此边框,在ImageView中使用语句为android:background="@drawable/editBorder"

This should solve your problem. 这应该可以解决您的问题。 :) :)

ImageView having two property android:background and android:src ImageView有两个属性android:backgroundandroid:src

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

Create a blank white frame with drop shadow(Photoshop recommended). 使用投影创建一个空白框(建议使用Photoshop)。

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>

This can be done with proper padding and 9 patch image. 这可以通过适当的填充和9补丁图像来完成。 See this link , may be it can help you. 看到这个链接 ,可能会对你有帮助。

I found this imageView . 我找到了这个imageView It's may good for you 这对你有好处

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM