Android ImageView,adjustViewBounds 在 Android 4.1 中不起作用

标签 android gridview imageview

在我的实现中,adjustViewBounds=true 在 android 5.1 中完全符合预期 但在 4.1 中不做同样的事情

4.1 on left, 5.1 on right

adjustViewBounds=true

enter image description here

adjustViewBounds=false

enter image description here

MainFragment

<GridView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:columnWidth="150dp"
    android:numColumns="auto_fit"
    android:verticalSpacing="0dp"
    android:horizontalSpacing="0dp"
    android:stretchMode="columnWidth"
    tools:context=".MainFragment"
    android:id="@+id/movie_gridView">
</GridView>

ImageView

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    <ImageView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:id="@+id/gridView_moviePoster"
        android:adjustViewBounds="true"/>
</FrameLayout>

最佳答案

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.

所以在 Api 级别 17 及以下你必须使用 AdjustableImageView

在gradle下面添加

compile 'com.inthecheesefactory.thecheeselibrary:adjustable-imageview:1.0.0'

详细教程See this

关于Android ImageView,adjustViewBounds 在 Android 4.1 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35450319/

相关文章:

Android在 GridView 上制作操作栏覆盖

java - 如何在 Android Studio 中从 java 类意向到 kotlin 类

Android Gradle 插件 : Property 'applicationId' is not annotated with an input or output annotation

c# - 将 `DataGrid` 替换为 `GridView` 时我们必须更改哪些内容?

java - 当另一个声音播放时停止播放上一个声音

javascript - jQuery 如何通过列的值选择表行组?

asp.net - 如何根据行绑定(bind)到的对象的属性设置 GridView 行的 RowStyle

android - 在 Android 上根据屏幕尺寸调整图像大小

Java Android 动态更改 ImageView 的位置

android - 动态设置ImageView的来源android