android - ImageView adjustViewBounds 好像不行??(不同项目不同结果)

标签 android imageview

我试图在保持宽高比的同时使用与父宽度匹配的 ImageView。 1个项目的结果符合预期。但在其他情况下,相同的代码会给出不同的结果。

仅供引用,布局来自两个不同的项目,而不是同一个项目。有人可以帮助我吗?

![项目 1 布局][1]

    <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#000000" >

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:adjustViewBounds="true"
            android:src="@drawable/news_holder" />

</RelativeLayout>

![项目2布局][2]

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#000000" >

    <ImageView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:src="@drawable/news_holder" />

</RelativeLayout>

最佳答案

你应该设置你的 targetSDK 19 它给出了预期的结果。但是当设置为 17 时,问题就来了。从文档来看,这应该是原因。

注释来自 the docs :

If the application targets API level 17 or lower, adjustViewBounds will allow the drawable to shrink the view bounds, but not grow to fill available measured space in all cases. This is for compatibility with legacy MeasureSpec and RelativeLayout behavior.

关于android - ImageView adjustViewBounds 好像不行??(不同项目不同结果),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24256971/

相关文章:

java - 如何将另一个项目中的应用程序用作库?

Android 如何从响应的 DefaultHttpClient 保存 cookie?

android - ImageView ArrayList 给出 NullPointerException

android - 在相机预览中将 ImageView 定位为叠加图像

java - 如何在 ListView 中无延迟地从网络下载图像?

Android 在视频缓冲时显示图像?

android - Cordova + Android - android-windowSoftInputMode adjustPan 不工作

android - Android中调试native代码的工具有哪些

java - 在 Android 中自定义文本编辑文本

Android:图库小部件和阴影