【发布时间】:2017-03-22 07:11:18
【问题描述】:
图像的尺寸可能比设备大。我想缩放图像,使其始终采用全宽和可变长度的 height ,同时保持纵横比。
我还想在滚动时设置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>
目前它不保持纵横比。
【问题讨论】:
-
试试这个,stackoverflow.com/a/42693248/5471104,这里的高度等于宽度,你可以计算纵横比并相应地重新初始化高度。但另一方面,由于您使用的是折叠工具栏,请使宽度和高度与父级匹配。这不会破坏应用的整体外观。
-
@Rico 我期待可以通过 XML 单独完成的事情
-
哦,我明白了,我几乎不使用 xml ,所以不敢使用它们 :(
-
对不起@Varuog,我刚刚检查过,当您有预定义的纵横比时,即使 PercentRelativeLayout 也有帮助。动态更改仅通过代码起作用。您可能可以创建一个自定义 ImageView 来处理视图中的这些更改
标签: android imageview android-glide