【问题标题】:Add Frames or Borders to images in Android在 Android 中为图像添加框架或边框
【发布时间】:2013-02-02 13:10:41
【问题描述】:

我是 Android 应用程序开发的新手,我想创建一个应用程序,我可以在其中为图库中的图像添加边框或框架。我搜索了一些博客,但没有得到答案。

我想这样创作 https://play.google.com/store/apps/details?id=com.tndev.loveframes&hl=en

谁能告诉我有关如何执行该应用程序的想法或任何概念?

【问题讨论】:

标签: android border image-editing


【解决方案1】:

以编程方式:

ImageView i = new ImageView(mContext);
Drawable d = null;
i.setImageDrawable(d);
        i.setAdjustViewBounds(true);
        i.setScaleType(ScaleType.CENTER_INSIDE);
        i.setBackgroundColor(Color.WHITE); //providing color to the background. 
        i.setPadding(3,3,3,3);//providing padding to the image.
        i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));

要将一张图片覆盖在另一张图片上,请使用 Canvas 类并检查以下链接: Android: How to overlay-a-bitmap/draw-over a bitmap?

【讨论】:

【解决方案2】:

方法1.如果你想要边框,你可以把你的imageView放在一个布局中。

然后为布局设置背景颜色

为布局提供填充,以便图像和布局有空间(可以看到背景颜色)

方法2。您可以使用相对布局并将图像(第一个图像视图)放在边框(第二个图像视图)上。为此,边框应具有精确的大小。

示例布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Bottom layer -->
<ImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="bkgrnd"/>
<!-- Middle layer -->
<ImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="your_pic"/>
<!-- Top Layer -->
<ImageView 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="ribbon_pic"/>

【讨论】:

  • 我需要类似这个链接play.google.com/store/apps/…
  • 我已经编辑了答案。请查看示例布局部分
  • 您可以在第一个 imageView 中设置背景图像,在第二个图像视图中设置您的图片,以及在最后一个图像视图中位于图像顶部的功能区图像。然后,您可以使用 margin 属性将图像左右移动一点以获得大致位置。
  • 您还必须获取图像的大小并以编程方式缩放功能区以相应地适应。
猜你喜欢
  • 2015-01-29
  • 2013-01-22
  • 1970-01-01
  • 2020-05-19
  • 2013-02-27
  • 1970-01-01
  • 2013-01-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多