【发布时间】:2011-08-05 13:25:01
【问题描述】:
我已经搜索、摆弄和哭了好几个小时,但不知道如何将图像放入 ImageView 并让图像显示为未缩放、右对齐以及裁剪超出 ImageView 左侧的溢出.
ImageView 是这样定义的:
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="@drawable/bleh"
></ImageView>
layout_width 设置为 fill_parent 以拉伸和缩小 ImageView 以适应屏幕。
layout_height 设置为 wrap_content,因为 ImageView 将始终具有固定的高度,由图像确定。
我没有定义layout_gravity="right",因为我的理解是这与 ImageView 在其父级中的定位有关,在这种情况下它没有任何影响,因为 ImageView 的宽度设置为 fill_parent。
使用上面的布局代码,图像缩放以适应 ImageView。我可以防止缩放的唯一方法是设置android:scaleType="center",它可以防止缩放,但不幸的是图像居中。
有什么想法吗?否则,我目前正在玩弄以下替代方案:
- 继承 ImageView 并实现我自己的 onDraw() 方法。
- 将全图大小的 ImageView 放入 ScrollView 并将滚动固定到最右侧(并禁用任何表明它是滚动视图的指示)。
【问题讨论】:
标签: android imageview crop alignment