![](/img/trans.png)
[英]It is possible to use ScaleType CENTER_CROP but without centering the image vertically? (showing the top of the image)
[英]Center image horizontal in imageView without centering it vertically
我有动态尺寸的图像和具有统计高度的ImageView
。 我试图像这样在我的imageView
绑定我的图像。
我的意思是水平填充
ImageView
,而不垂直填充。 这是我的代码
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="280dp">
<ImageView
android:id="@+id/exploreImage"
android:src="@drawable/beard1"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
但是ImageView
现在ScaleType
,它允许这种方式绑定。
您有关于如何做的任何想法吗?
将其放在scrollview
然后将imageview
scrollview
代码更改为:
<ImageView
android:id="@+id/exploreImage"
android:src="@drawable/beard1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
/>
跟随xml产生的输出与您想要的非常相似。 只需提供所需的高度,使其低于图像的高度即可。
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:scaleType="matrix"
android:src="@drawable/image_1" />
实际上, ScaleType.Matrix
意味着使用图像矩阵进行缩放,稍后在绘制时应在代码中提供该图像矩阵。 当您设置scaleType="matrix"
但未在代码中提供矩阵时; 那么它不会缩放,而是从顶部开始裁剪图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.