关于ImageView图片宽高比的问题

在Android的ImageView中图片宽高显示不友好,为了更明显地体现问题,给ImageView加了个chat_to_bg_normal.9.png(<a href="https://isux.tencent.com/android-ui-9-png.html">关于.9.png</a>)作为background。

正常情况下,有些不是正方形的图片会显示得不是那么友好:

<ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="5dp"
      android:src="@drawable/kobe2"
      android:background="@drawable/chat_to_bg_normal"
      android:visibility="visible"
      />
QQ图片20170502184615.png

在加上android:adjustViewBounds="true" 之后按照图片本身的轮廓友好显示:

<ImageView
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:padding="5dp"
      android:adjustViewBounds="true"   
      android:src="@drawable/kobe2"
      android:background="@drawable/chat_to_bg_normal"
      android:visibility="visible"
      />
QQ图片20170502184545.png

<a href="https://developer.android.com/reference/android/widget/ImageView.html">AndroidDeveloper官网</a>的文档截图:

QQ图片20170502190028.png

意思是如果把这个属性设置为true的话,ImageView会通过调整边界值来保留图片的正常宽高比。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Android 自定义View的各种姿势1 Activity的显示之ViewRootImpl详解 Activity...
    passiontim阅读 174,650评论 25 709
  • 刚刚上大学,人生地不熟,就认识一帮舍友,为了显示我助人为乐的好形象,开学的时候舍友常常@我打饭,我都义不容辞,于是...
    会计1171杨小燕阅读 253评论 0 0
  • 在我接触过的很多痘痘MM里面,90%都是上火下寒的痘痘患者。所以把这一小节单独拿出来给大家说这个问题。 我的微信:...
    唯美感情学阅读 2,074评论 6 3
  • 桥接模式 针对接口编程,就是桥接模式 策略模式 策略模式也可看作是针对接口编程 状态模式 状态模式通过 Conte...
    wyrover阅读 401评论 0 0
  • 翻出去年去马尔默的照片 后悔没有多欣赏欣赏风景,想开一个风景系列就叫#假装自己在瑞典#
    漂亮拖鞋阅读 312评论 3 3