ImageView与右对齐,裁剪,未缩放的内容
问题描述:
我一直在搜索,摆弄和哭了几个小时,但无法弄清楚如何将图像放入ImageView并使图像呈现未缩放,右对齐并具有超出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"
,这可以防止缩放,但不幸的是会使图像居中。
Ay的想法?否则,我正在玩弄以下替代方法:
- 子类ImageView并实现我自己的onDraw()方法。
- 将全图像大小的ImageView放入ScrollView并将滚动修复到最右侧(并禁用任何指示它是滚动视图)。
答
取代滚动视图 - 将图像放入LinearLayout或RelativeLayout中。制作布局的layout_width fill_parent和layout_height包装内容。然后在ImageView上使用layout right和wrap_content作为宽度和高度。
<LinerLayout android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView android:layout_gravity="right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bleh"/>
</LinearLayout>
答
@harmanjd:你已经做了一些错误,这是正确的方式: (抱歉,我不能评论你的答案)
<LinearLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/bleh"/>
/>
</LinearLayout>
谢谢!!极大喜欢! :D – voodoo98 2015-02-26 17:59:48