【问题标题】:Imageview shows border around photo that does not exist in the source imageImageview 显示源图像中不存在的照片周围的边框
【发布时间】:2017-01-04 19:56:15
【问题描述】:

我试图在imageview 中显示一个简单的图像,它似乎在照片周围添加了源图像中不存在的边框。我将imageview 放在父视图中并将图像设置为它,在编辑器中您可以看到一小块边框,但是当我在设备或模拟器上运行它时,会出现更多边框。

我尝试从照片大小中删除一个像素,以防出现边框,但这并没有解决问题。下面是模拟器和编辑器的照片,以显示差异。

编辑:

模拟器:

任何帮助将不胜感激,谢谢。

编辑:添加 xml 文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_home_screen"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="frolicindustries.strandstudybible.HomeScreen"
android:weightSum="1"
android:background="@android:color/background_light"
android:orientation="vertical"
android:baselineAligned="false">
<!--android:scaleType="fitCenter"-->
<!--android:cropToPadding="false"-->
<!--android:layout_weight="0.01"-->

<Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:id="@+id/About"
    android:background="@drawable/aboutgradient"
    android:layout_alignParentBottom="true"
    android:layout_height="65sp"
    android:layout_marginBottom="1dip"
    android:layout_marginTop="1dip"
    android:layout_alignRight="@+id/Extras"
    android:layout_alignEnd="@+id/Extras"
    android:layout_alignLeft="@+id/Bible"
    android:layout_alignStart="@+id/Bible" />

<Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:id="@+id/Extras"
    android:background="@drawable/extragradient"
    android:layout_height="65sp"
    android:layout_above="@+id/About"
    android:layout_marginTop="1dip"
    android:layout_alignRight="@+id/WTFW"
    android:layout_alignEnd="@+id/WTFW"
    android:layout_alignLeft="@+id/Bible"
    android:layout_alignStart="@+id/Bible" />

<Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:id="@+id/Bible"
    android:background="@drawable/biblegradient"
    android:layout_alignParentLeft="true"
    android:layout_alignParentStart="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:elevation="0dp"
    android:layout_height="65sp"
    android:layout_marginLeft="-5dip"
    android:layout_marginRight="-5dip"
    android:layout_above="@+id/WTFW" />

<Button
    android:text="Button"
    android:layout_width="wrap_content"
    android:id="@+id/WTFW"
    android:background="@drawable/wtfwgradient"
    android:layout_height="65sp"
    android:layout_above="@+id/Extras"
    android:layout_marginTop="1dip"
    android:layout_alignRight="@+id/Bible"
    android:layout_alignEnd="@+id/Bible"
    android:layout_alignLeft="@+id/Bible"
    android:layout_alignStart="@+id/Bible" />

<ImageView
    android:id="@+id/imageView2"
    android:src="@drawable/logo"
    android:background="@null"
    tools:targetApi="lollipop"
    android:layout_width="match_parent"
    android:adjustViewBounds="false"
    app:srcCompat="@drawable/logo"
    android:layout_alignRight="@+id/Bible"
    android:layout_alignEnd="@+id/Bible"
    android:layout_height="155sp" />

<ImageView
    android:layout_width="match_parent"
    android:src="@drawable/title"
    android:id="@+id/imageView3"
    android:layout_weight="0.29"
    android:layout_height="wrap_content"
    android:layout_above="@+id/Bible"
    android:layout_alignRight="@+id/imageView2"
    android:layout_alignEnd="@+id/imageView2"
    android:cropToPadding="false"
    android:scaleType="centerCrop"
    android:adjustViewBounds="true"
    android:layout_below="@+id/imageView2" />
</RelativeLayout>

【问题讨论】:

  • 这是一个 9-patch-image 吗?
  • 我相信是的,我有一个工具可以从源文件生成不同比例的图像
  • 请发布您的 xml 文件。
  • @staticFlow 也许你用过wrap_content ?尝试使用 src 在您的图像视图中添加背景颜色,并查看边框颜色是否发生变化。如果是,您的图像很小并且您将其包裹起来!如果不是,您的图像重新设计有问题。
  • @Charuka 我添加了一个背景,它确实显示在它后面,但图像未设置为 wrap_content

标签: android imageview


【解决方案1】:

检查一下,

我的 xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/content_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center"
    android:background="#000"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context="com.example.charu.its2017huree.MainActivity"
    tools:showIn="@layout/app_bar_main"
    android:orientation="vertical">


 <ImageView
     android:background="#FFF"
     android:src="@drawable/amanda"
     android:id="@+id/my_image_view"
     android:layout_width="match_parent"
     android:layout_height="300dp" />


</LinearLayout>

我设置了一个imageView,我发现它的左右边缘似乎有问题。我已经给我的 imageView 提供了match_parent。所以我给我的imageView 添加了一个背景颜色来看看发生了什么。

但这对我来说还不够,我还想看到边界。它在你的安卓手机上!

设置>开发者选项>(向下滚动)类别绘图下有一个选项显示布局边界 >勾选该选项 .. mm你得到某种网格在您的手机中。取消勾选该选项后它会消失是正常的。

让我们跳回到图像视图,看看它现在的样子!

  1. 现在我可以清楚地看到我在图像后面添加的背景颜色
  2. 图像视图宽度边界也很好,它是match_parent。您可以从您的布局边界中看到。

MM 听起来图像不合适,然后我尝试使用 scaleType 之类的 android:scaleType="fitXY" 并运行,看看现在怎么样.. 好吧,看来她已经占据了全部空间.. 我的意思是我的imageView:D

这样您就可以清楚地确定您的imageView 出了什么问题

【讨论】:

  • 嘿..你..是的你..别看她!!!如果它有帮助,请点赞:D
  • 您使用的是什么 IDE?我似乎无法在 android studio 中找到该选项。
  • @staticFlow 它不是来自 android studio 而是来自 OS android。它在你的手机上
  • @staticFlow 这有助于解决您的问题吗?或者你还有它
  • 是的,谢谢!将其更改为 fitXY 就是这样做的
【解决方案2】:

您的图像保存为什么?我建议使用 .png 扩展名。当我的图像是 jpg 或其他任何东西时,我会得到边框。

【讨论】:

  • 图片为png格式的高分辨率矢量图形文件,谢谢建议:)
猜你喜欢
  • 2011-06-12
  • 2011-08-20
  • 1970-01-01
  • 2011-06-08
  • 2016-08-15
  • 1970-01-01
  • 2011-08-22
  • 2012-02-11
  • 2012-09-16
相关资源
最近更新 更多