ImageView 图片靠右,靠左处理

相信在工作中很多人都会遇到ImageView需要图片靠左和靠右,典型的案例就是悬浮窗缩进的小图片,前几天在工作中遇到,随手一记。

  • 简单介绍下布局文件
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="horizontal" >    <ImageView        android:id="@+id/button6"        android:layout_width="60dp"        android:layout_height="60dp"        android:src="@drawable/ourpalm_float_half_left"        />LinearLayout>

这个时候如果不做任何处理,而且想让图片靠左的话,实际的显示效果是这样的

到这里脑子突然卡住了,好久没调这个,然后经过研究发现:

<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:orientation="horizontal" >    <ImageView        android:id="@+id/button6"        android:layout_width="60dp"        android:layout_height="60dp"        android:src="@drawable/ourpalm_float_half_left"        android:scaleType="fitStart"        />LinearLayout>
  • 这个时候会惊喜的发现

  • 加入android:scaleType=”fitStart” 后,图片乖乖的靠左,查了安卓的文档:
    android:scaleType=”fitStart” 把图片按比例扩大(缩小)到View的宽度,显示在View的上部分位置。关键字:按比例缩放,靠左显示全图,
    很简单的解决问题,
  • 如果靠右的话,android:scaleType=”fitEnd” 加入这个就可以了,至于这个悬浮窗是在左还是在右显示,就需要代码逻辑判断了,这个就不多说了。

    是不是很简单的解决了问题,android的确勃大茎深,有时候很简单的配置解决复杂的问题,顺手一记,老司机轻喷.

更多相关文章

  1. uni-app系统目录文件上传(非只图片和视频)解决方案
  2. Android(安卓)OpenGL ES学习笔记之图形变换
  3. Android中图片的上传和下载
  4. android的网络通讯(Http通讯)封装类
  5. 基于Android(安卓)Webview的Hybrid App开发的前端优化
  6. Android四大图片缓存框架之-Fresco(一)
  7. Android(安卓)UI之ImageView
  8. 调用手机的摄像头,并且返回照片显示在程序界面上.
  9. httpClient及android 原生接口实现下载并显示图片

随机推荐

  1. 【精品教程】Android应用开发入门教程(经
  2. android的触摸屏事件
  3. android音乐播放器源码
  4. Android VNC Server on G1 (PC 远程控制
  5. Android开发之android命令大全
  6. Theme.NoTitleBar问题
  7. 自定义android RadioButton样式
  8. Android 检测更新库
  9. android noTouch 事件
  10. 使用SDK Manager更新时出现问题