2014-06-28 53 views
1

我需要我的应用程序中的图像图具有边框有点像如下:的Android - 添加自定义边框图像视图

enter image description here

我只有边框的图像,以及imageview,并以某种方式需要适合边框内的图像(边框图像是透明的 - 就像在这个问题中使用的是从here下载)。

有关如何实现此目的的任何建议?

+2

下载,你可以使用一个形象,那中心是透明的,则适合另一个ImageView的上 –

回答

1

有许多解决方案,你可以做。

  • 扩展的ImageView的类并重写的OnDraw(画布),并使​​用了油漆和着色画上的ImageView的画布图像,并提供矩形的大小来笼络然后绘制框架。

  • 将ImageView的背景设置为Frame和Ur图像作为Src,给出一个填充,这将使Src图像适合透明区域内。

+0

他们都不是足够多的好,成为通用 – deadfish

1

尝试此,将其保存为 “frame.9.png” 作为9patch,它下降到可绘文件夹:

enter image description here

Exampe PIC中帧,它应该是更大的,例如:

enter image description here

实施例作为布局:

<?xml version="1.0" encoding="utf-8"?> 

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:background="@drawable/frame"> 

    <ImageView 
     android:layout_gravity="center" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:src="@drawable/cat" 
     android:adjustViewBounds="true" 
     android:scaleType="centerCrop" 
     /> 
</LinearLayout> 

结果:

enter image description here

记住,9补丁不能缩水,他们可以伸展。资讯:https://stackoverflow.com/a/14274623/619673

猫形象从http://www.socwall.com/wallpapers/search:cat/