【问题标题】:Android ImageView will not match_parent widthAndroid ImageView 不会 match_parent 宽度
【发布时间】:2012-09-29 04:57:59
【问题描述】:

我有一个 1x20 像素的 ImageView。该图像是 .9.png。我正在尝试使用 match_parent 但是当我在我的设备上运行应用程序时,它不会被拉伸以填充屏幕的宽度。这是 ImageView 的 XML 中的代码

<ImageView
  android:id="@+id/dividerBar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:src="@drawable/ic_bar" 
  android:layout_gravity="center_horizontal"
  android:scaleType="centerInside" />

关于如何让 ImageView 覆盖整个屏幕宽度的任何想法?

【问题讨论】:

    标签: android android-layout imageview


    【解决方案1】:

    如果是 9 补丁,则需要将其设置为 imageview 的背景属性才能正确缩放。现在它正在尝试使用您提供的 scaleType 标签来缩放图像,就像它对任何其他图像一样。

    尝试设置

    android:background="@drawable/ic_bar" 
    

    并删除 src 属性

    此外,如果您仅使用 imageView 来显示 9-patch,您可以切换到使用常规 View 而不是 ImageView。只要设置背景属性就可以了。

    【讨论】:

    • 成功了。感谢您快速而有帮助的回复。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多