ImageView全宽和可变高度,同时保持纵横比

时间:2017-03-22 07:11:18

标签: android imageview android-glide

图像可能比设备更大。我想缩放图像,使其始终采用全宽和可变长度,同时保持纵横比。

此外,我想在滚动时设置Imageview的特定最小高度。在指定的最小高度ImageView之后应固定。

 <android.support.design.widget.AppBarLayout
        android:id="@+id/foo"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/grey_dark_transparent">

        <!--
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/grey_dark_transparent"
            app:layout_collapseMode="parallax"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
            -->
        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|exitUntilCollapsed">

            <ImageView
                android:id="@+id/wallpaper_banner"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:scaleType="fitXY"
                android:adjustViewBounds="true"
                android:src="@drawable/wallpaper_placeholder" />
        </android.support.design.widget.CollapsingToolbarLayout>

        <!-- @Banner -->

    </android.support.design.widget.AppBarLayout>

目前它没有保持宽高比。

1 个答案:

答案 0 :(得分:0)

使用ScaleType android:scaleType="centerInside",如下面的代码。它始终处理图像纵横比。

  <ImageView
        android:id="@+id/wallpaper_banner"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:scaleType="centerInside"
        android:adjustViewBounds="true"
        android:src="@drawable/wallpaper_placeholder" />
相关问题