我有一个显示矩形图像的 ImageView。我想显示对从自定义相机 Activity 中捕获的图像的评论。
问题是捕获的图像(在高度上)大于 View ,因此按 X 缩放以适合 Y。
如图所示,图像右侧有一条白色条纹。我想要的是让图像填满 View 的宽度,然后剪裁或隐藏底部多余的部分。
我尝试了很多不同的配置,但似乎无法正常工作。目前我有:
<FrameLayout 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:clipChildren="true"
android:clipToPadding="true">
<ImageView
android:id="@+id/camera_review"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitStart" />
....
</FrameLayout>
图像将被裁剪到方形视口(viewport)中,因此从顶部|左侧显示图像并填充宽度非常重要。
我能够让它工作的一种方法是将 ImageView 放入 ScrollView,但随后我必须隐藏滚动条,并弄清楚如何禁用滚动。
最佳答案
根据 Moradiya Akash 的回答,图像将适合您的 ImageView
但宽高比不准确。 Steve Haley 给出了关于保持纵横比的答案。
确保使用 android:src="..."
而不是 android:background=".. 将图像设置到
。 ImageView
”src=
使其缩放图像保持纵横比,但 background=
使其缩放和扭曲图像以使其完全适合 ImageView< 的大小
.
更多 here
关于android - ImageView 填充父级的宽度,裁剪任何额外的高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26926307/