Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android-向图像视图添加自定义边框_Android_Android Imageview - Fatal编程技术网

Android-向图像视图添加自定义边框

Android-向图像视图添加自定义边框,android,android-imageview,Android,Android Imageview,我需要在我的应用程序中有一个具有边框的图像视图,如下所示: 我只有边框的图像和imageview,并且需要在边框内安装imageview(边框图像是透明的,就像这个问题中使用的图像是从下载的) 关于如何实现这一点,您有什么建议吗?您可以做很多解决方案 扩展ImageView类并覆盖OnDraw(画布),使用paint和shader在ImageView的画布上绘制图像,并提供要绘制的矩形的大小,然后绘制帧 将ImageView的背景设置为Frame,将Ur图像设置为Src,从而为图像添加填充,

我需要在我的应用程序中有一个具有边框的图像视图,如下所示:

我只有边框的图像和imageview,并且需要在边框内安装imageview(边框图像是透明的,就像这个问题中使用的图像是从下载的)


关于如何实现这一点,您有什么建议吗?

您可以做很多解决方案

  • 扩展ImageView类并覆盖OnDraw(画布),使用paint和shader在ImageView的画布上绘制图像,并提供要绘制的矩形的大小,然后绘制帧

  • 将ImageView的背景设置为Frame,将Ur图像设置为Src,从而为图像添加填充,使Src图像适合透明区域

尝试此操作,将其另存为“frame.9.png”作为9patch,将其放入drawables文件夹:

例如,框架中的图片应该更大,例如:

布局示例:

<?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>

结果:

记住,9-patch不能收缩,它们可以拉伸。此处的信息:


Cat图像是从下载的

您可以使用一个中心透明的图像,然后在其上安装另一个图像视图