如何显示边框若要ImageView的? [英] How To Display Border To Imageview?

查看:156
本文介绍了如何显示边框若要ImageView的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友如何显示边框若要ImageView的?

Friends How To Display Border To Imageview ?

我想结果,如移动画廊所有图像显示边框。

I Want To Result Like Mobile gallery all image display with border.

PLZ给我答感谢提前....

plz give me ans thanks for advance....

推荐答案

您可以为您的的ImageView 的边界创建资源(层绘制XML)(实际上背景),并宣布在主题的ImageView 的背景资源是可绘制的XML。

You can create a resource (layer drawable xml) for your ImageView's "border" (actually background), and declare in your theme that the ImageView's background resource is the drawable xml.

如果你需要这个边界,以根据的ImageView 的状态(聚焦更改,选择等),那么你就应该创造更多的层可绘,并把它们连成一个选择XML(州绘制)。
然后在你的主题,你应该设置的ImageView 的背景是这样的 selector.xml

If you need this "border" to be changed based on the ImageView's state (focused, selected, etc.), then you should create more layer drawables, and put them together into a selector xml (state drawable).
Then in your theme you should set the ImageView's background to be this selector.xml.

更新
下面是如何指定一个简单的边框,以图像样本,这将导致在

Update
Below is a sample of how to specify a simple border to your images, that will result in

您必须

  1. 创建一个新的图层绘制文件( image_border.xml ),
  2. 修改/创建 styles.xml 文件
  3. 修改/创建 colors.xml 文件
  4. 修改您的布局xml文件(或code)的样式应用到的ImageView
  1. create a new layer drawable file (image_border.xml),
  2. modify/create your styles.xml file
  3. modify/create your colors.xml file
  4. modify your layout xml file (or your code) to apply the style to the ImageView.

RES /绘制/ image_border.xml

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item>
        <shape android:shape="rectangle">
            <gradient android:angle="90" 
                android:startColor="@color/image_border_start" 
                android:centerColor="@color/image_border_center"
                android:endColor="@color/image_border_end" />
        </shape>
    </item>
    <item android:top="2dp" android:left="2dp" 
        android:right="2dp" android:bottom="2dp">
        <shape android:shape="rectangle">
            <solid android:color="@color/default_back_color" />
        </shape>
    </item>
</layer-list>

RES /价值/ styles.xml
添加以下行:

res/values/styles.xml
Add the following lines:

<style name="myImageView">
    <!-- 3dp so the background border to be visible -->
    <item name="android:padding">3dp</item>
    <item name="android:background">@drawable/image_border</item>
    <item name="android:scaleType">fitCenter</item>
</style>

RES /价值/ colors.xml
添加以下行:

res/values/colors.xml
Add the following lines:

<color name="image_border_start">#40990000</color>
<color name="image_border_end">#FF660000</color>
<color name="image_border_center">#FFFF3333</color>

最后指定的ImageView 在你的样式您的布局XML

<ImageView android:id="@+id/my_image" 
    android:layout_width="100dp" android:layout_height="100dp"
    android:src="@drawable/efteling"
    style="@style/myImageView" />

这篇关于如何显示边框若要ImageView的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆