【问题标题】:ImageView inside a RelativeLayout unwanted line在 RelativeLayout 不需要的行内的 ImageView
【发布时间】:2015-08-10 22:49:30
【问题描述】:

我有一个结构如下的片段

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

    <TextView
        android:id="@+id/tv_title"
        style="?android:tileMode"
        android:layout_width="match_parent"
        android:layout_height="100dp"
        android:minHeight="100dp"
        android:layout_alignParentTop="true"
        android:fontFamily="sans-serif-light"
        android:textSize="25sp"
        android:gravity="center"
        android:textColor="@android:color/white"
        android:textAlignment="center" />

    <ImageView
        android:id="@+id/iv_image"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_below="@id/tv_title"
        android:contentDescription="@string/image"
        android:layout_gravity="center_horizontal"
        android:adjustViewBounds="true"
        android:cropToPadding="false"
        android:scaleType="fitXY"/>

</RelativeLayout>

问题是 TextView 和 ImageView 之间出现了不需要的线。
我尝试了很多不同的位置和图像尝试,但我无法让这条线消失。

顺便说一句,所有这些都在一个扩展了 FragmentActivity 的 Activity 中。

【问题讨论】:

  • 你能发张照片吗?它将帮助我诊断您所指的线路。
  • 您使用的是 9 补丁吗?因为这看起来真的很像典型的malformed 9 patch
  • 感谢@FrankN.Stein 的快速回答。我使用了 9 个补丁来生成图像。我想你是对的。有一个已知的解决方法或自动生成图像的替代方法吗?谢谢
  • 我用的是普通的图形编辑器,然后用draw9patch工具检查一下。深入了解 9 个补丁规则至关重要。查找有效帮助here。显然,如果在设置 9 个补丁标记之后缩放图像,您将丢失它们,因为颜色将被混合(用于抗锯齿)。
  • 太好了,谢谢,解决方案是使用图形工具进行编辑并使用 draw9patch 进行检查。 @FrankN.Stein 请作为答案发布,我将标记为正确答案。

标签: android android-layout android-fragments imageview android-fragmentactivity


【解决方案1】:

这个问题看起来像一个典型的格式错误的 9 补丁

要编辑 9 补丁,我使用普通的图形编辑器,然后使用 draw9patch 工具进行检查。

深入了解 9 个补丁规则至关重要。
查找有效帮助here

显然,如果您在设置 9 个补丁标记之后缩放图像,您将丢失它们,因为颜色会被混合(图形工具往往会应用抗锯齿)。


另外,别忘了要正确设置 9 补丁,它必须是 View 或 Layout 的背景,才能被拉伸以适应。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-08-07
    • 2018-07-07
    • 1970-01-01
    • 1970-01-01
    • 2023-03-25
    • 2015-10-20
    • 1970-01-01
    • 2011-08-15
    相关资源
    最近更新 更多