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> 
+0

谢谢!!极大喜欢! :D – voodoo98 2015-02-26 17:59:48

@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> 
+0

我希望TextView(用于名称)和Imageview(用于图像)在一行中,并且我希望TextView左algn和Imageview右对齐。你能给我一个建议吗? – CSharp 2012-06-28 05:01:25

+1

对不起,我认为这是不正确的方式来要求建议...此帖有另一个要求 – Ging3r 2012-07-02 13:16:14