【问题标题】:Can't adjust ImageView on Android API below 16无法在 16 以下的 Android API 上调整 ImageView
【发布时间】:2015-08-06 11:21:51
【问题描述】:

我想在我的应用程序中设置一个背景图像,如果需要,它将填充所有屏幕和缩放,所以我在 main_layout.xml 中设置它:

<ImageView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:adjustViewBounds="true"
    android:id="@+id/imageView"
    android:src="@drawable/bg_iphone_6_plus" />

它看起来像这样

不太好,其实我也需要这张图调整宽度。

好的,所以这在大多数情况下都适用,并且所有 API 都高于 16,但是当我在 api 低于 16 ( minTargetSdk=14 ) 上运行我的应用程序时,我看到了:

我不知道为什么会这样,我已经尝试过tutorial,并将 ImageView 替换为 com.inthecheesefactory.thecheeselibrary.widget.AdjustableImageView

但它并没有改变任何东西

【问题讨论】:

    标签: android android-layout imageview adjustment


    【解决方案1】:

    尝试在 ImageView 布局中将 android:src 属性替换为 android:background。我认为这将解决您的问题。如果问题仍然存在,请告诉我。

    【讨论】:

      【解决方案2】:

      如果你的背景图片只是这张中间有渐变的灰色图片,那么将drawable移动到android:background到父容器。你不需要额外的ImageView

      但是,如果您想将位图设置为背景并保持此图像在不同设备和方向上的比例,您应该使用ImageView 及其android:scaleType,例如"centerCrop"通常是背景的最佳选择)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2011-10-02
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多