【问题标题】:ImageView with right-aligned, cropped, unscaled content具有右对齐、裁剪、未缩放内容的 ImageView
【发布时间】: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


    【解决方案1】:

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

    【讨论】:

    • 我希望 TextView(用于名称)和 Imageview(用于图像)在一行中,并且我希望 TextView 左对齐和 Imageview 右对齐。你能给我一个方法吗?
    • 对不起,我认为请求建议的方式不正确...这篇文章有另一个请求
    【解决方案2】:

    而不是滚动视图 - 将图像放在 LinearLayout 或 RelativeLayout 内。使布局的 layout_width fill_parent 和 layout_height 包装内容。然后在 ImageView 上使用布局重力右和 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>
    

    【讨论】:

    • 谢谢!!极端大喜欢! :D
    猜你喜欢
    • 2012-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-29
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多