【问题标题】:ImageView's image is positioned wrong at horizontal orientationImageView 的图像在水平方向定位错误
【发布时间】:2016-03-05 03:03:40
【问题描述】:

我创建了一个安卓应用。现在,当方向为垂直时,图像加载正常,并且我希望它以正确的方式喜欢这个

` 但是当我水平转动设备时,此图像设置在图像视图的左角

imageview的xml如下`

        <ImageView
            android:id="@+id/backdrop"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:scaleType="matrix"
            android:fitsSystemWindows="true"
            app:layout_collapseMode="parallax" />

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
            app:layout_collapseMode="pin" />

what is the reason causing this behavior ?? is it due toandroid:scaleType="matrix"` 属性 ??任何帮助将不胜感激。

【问题讨论】:

    标签: android xml imageview


    【解决方案1】:

    由于 ImageView 的 scaleType,如果您希望图像填充整个容器,则需要使用不同的 scaleType,例如 fillXY 或 CenterCrop。

    如果你想掌握这个主题,你可以查看this 文章来比较每个 scaleType 并决定哪一个最适合你的需求。

    【讨论】:

    • 我真正想要的是图像的左上角应该与图像视图的左上角重合,因为海报比设备屏幕大得多。知道该怎么做吗??
    • 你可以试试 fitXY 看看效果如何……但我真的不明白你想要做什么。
    【解决方案2】:

    Matrix 可能不是您想要使用的。试试centerInsidecenterCrop,看看你最喜欢哪个。其他变体可以找到here

    【讨论】:

    • 没有 CENTER_INSIDE 或 CENTER_CROP 等值
    • @Infamous sorry 指的是程序化的设置方式,已经调整了我的帖子
    • 你知道图像的左上角应该如何与图像视图的左上角重合吗,因为海报比设备屏幕大得多。当设备垂直时' android:scaleType=" matrix" ' 做我想做的事
    • 我相当肯定centerCrop 也会完全满足您对垂直行业的要求。这并不意味着它是正确的。从横向视图来看,海报不大于横向屏幕。 Matrix 对图像的影响为 0,因为您没有设置矩阵
    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 2011-02-04
    • 1970-01-01
    • 2012-06-26
    • 2020-11-05
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多