【问题标题】:Internal border on ImageViewImageView 上的内部边框
【发布时间】:2015-03-25 09:42:03
【问题描述】:

我想在我的 ImageView 上放置一个内部边框,我设法用填充和背景做了一个外部边框,但我希望我的图像保持相同的大小(即使它的一部分被边框覆盖)所以我需要的是制作一个内部边框,但我不知道该怎么做,有什么建议吗?

提前感谢您的回答。

【问题讨论】:

  • 您的 ImageView 是否有固定大小?
  • 我怎么知道它是否是固定大小的?我试图以编程方式更改它的宽度/高度,但它没有做任何事情。我的 ImageView 在宽度和高度上都有 wrap_content ,但在一个重量为 0.2 的布局内(我认为这就是大小不变的原因)。我可以把我的 xml 放在这里,但它很复杂(它们在“包含”中“包含”..)

标签: android imageview border internal


【解决方案1】:

这是解决方案..

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:src="@drawable/ic_launcher" />

<LinearLayout
    android:layout_width="match_parent"
    android:background="@drawable/mBorder"
    android:layout_height="match_parent"></LinearLayout>

</FrameLayout>

mBorder.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >

   <stroke android:width="4dp"
    android:color="#ff00ffff" />

</shape>

【讨论】:

  • 这就是解决方案!谢谢你。只是一件事,将“”添加到 mBorder.xml 以避免用黑色背景覆盖 ImageView。
猜你喜欢
  • 1970-01-01
  • 2013-12-27
  • 1970-01-01
  • 1970-01-01
  • 2015-02-09
  • 1970-01-01
  • 2014-03-25
  • 2012-05-03
  • 1970-01-01
相关资源
最近更新 更多